【问题标题】:Insert data into Datagridview from comboboxes and textboxes to a specific row将数据从组合框和文本框插入 Datagridview 到特定行
【发布时间】:2020-09-17 10:07:14
【问题描述】:

所以基本上我想做的是从组合框中选择数据,并在文本框中写一些东西,当我按下按钮时,所有这些数据将填充 datagridview 的适当位置。

我只找到了填充彼此相邻的行的代码,但我必须为它们编写一些逻辑来填充特定行或不填充某些值

        private void fill_Click(object sender, EventArgs e)
    {

        table.Rows.Add(combo1.Text, combo2.Text, combo3.Text, text1.Text);
        dataGridView1.DataSource = table;
    
    }

仅当这些行和值应该彼此相邻时,此代码才会起作用。但就我而言,他们没有。

如何引用我要填充的特定行?

【问题讨论】:

    标签: c# database visual-studio datagridview windows-forms-designer


    【解决方案1】:

    您似乎正在向表中添加“新”行,所以我不确定您所说的“特定”行是什么意思?我假设您的意思是新行中的“特定列”?如果是这样的话,那么这应该工作......

    DataRow dr = table.NewRow();
    // by column Name...
    dr["Name"] = combo1.Text;
    // or by index
    int colIndex = 3;
    dr[colIndex] = text1.Text;
    // then add the row;
    table.Rows.Add(dr);
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    相关资源
    最近更新 更多