gpt4 book ai didi

c# - 使用文本框向 DataGridView 添加新行

转载 作者:行者123 更新时间:2023-12-02 15:56:45 25 4
gpt4 key购买 nike

我正在尝试从文本框添加到 datagridview 但代码不起作用

dataGridView1.Rows[0].Cells[0].Value = textBox6.Text;
dataGridView1.Rows[0].Cells[1].Value = textBox5.Text;
dataGridView1.Rows[0].Cells[2].Value = textBox7.Text;
dataGridView1.Rows[0].Cells[3].Value = dateTimePicker3.Value;

最佳答案

现在知道您确实处于表单项目中,这是我的建议。我看到另一个人已经建议了这一点,我添加了断言,以便如果任何 TextBox 控件为空,则不会添加行。

if ((!string.IsNullOrWhiteSpace(textBox6.Text)) || (!!string.IsNullOrWhiteSpace(textBox5.Text)) || (!string.IsNullOrWhiteSpace(textBox7.Text)))
{
dataGridView1.Rows.Add(new object[] {textBox6.Text,textBox5.Text,textBox7.Text,dateTimePicker3.Value });
}

关于c# - 使用文本框向 DataGridView 添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33462212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com