【问题标题】:How can I write to a textbox in C#, having a bindingSource?如何在 C# 中写入具有 bindingSource 的文本框?
【发布时间】:2021-07-28 17:55:07
【问题描述】:

这是我在 C# 中使用 Visual Studio 2019 编写的代码:

private String[] getClientData(String clientName)
{
    DataTable table = labelPrinterDBDataSet.Tables["clients"];
    DataRow[] datatable = table.Select("name = '" + clientName + "'");

    if (datatable.Length > 0)
    {
        DataRow row = datatable[0];
        String[] data = new String[row.ItemArray.Length];

        for (int i = 0; i < row.ItemArray.Length; i++)
        {
            data[i] = row.ItemArray[i].ToString();
        }
        return data;
    }
    else
    {
        return new string[0];
    }
}

private void nameListBox_SelectedIndexChanged(object sender, EventArgs e)
{
    textBox1.Text = nameListBox.GetItemText(nameListBox.SelectedItem);

    clientData = getClientData(textBox1.Text);

    textBox1.Text = clientData[1];
    textBox2.Text = clientData[2];
}

listBox 带有 bindingSource。

当我运行我的程序时,它确实允许我写入文本框,但是如果我从列表框中选择一些东西,我就不能再写入文本框了。

【问题讨论】:

    标签: c# .net winforms bindingsource


    【解决方案1】:

    经过一些研究,它似乎是 CauseValidation 属性,但我不知道具体原因。 我把它从真改成假,问题就解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      相关资源
      最近更新 更多