【问题标题】:Select Values from checked DataGridView Items从选中的 DataGridView 项中选择值
【发布时间】:2017-12-29 15:13:30
【问题描述】:

我的代码如下:

DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
actGrid.Columns.Add(chk);
chk.HeaderText = "Select";
chk.Name = "select";
chk.ReadOnly = false;

DataGridViewTextBoxColumn mc_no = new DataGridViewTextBoxColumn();
actGrid.Columns.Add(mc_no);
mc_no.HeaderText = "M/C Number";
mc_no.Name = "mc_no";
mc_no.Width = 200;
mc_no.ReadOnly = true;

DataGridViewTextBoxColumn act_name = new DataGridViewTextBoxColumn();
actGrid.Columns.Add(act_name);
act_name.HeaderText = "Name";
act_name.Name = "member";
act_name.Width = 262;
act_name.ReadOnly = true;

while (DR.Read())
{
    actGrid.Rows.Add(true, DR.GetInt32(0).ToString(), DR.GetString(2) + " " + DR.GetString(1));
}

产生以下输出:

现在我想根据选择的帐户执行一些操作(通过切换尾随复选框),尤其是 M/C 编号。

【问题讨论】:

    标签: c# .net winforms checkbox datagridview


    【解决方案1】:
    // iterate over DataGridView rows
    foreach (DataGridViewRow row in actGrid.Rows)
    {
        // check, if row is selected by checkbox
        if (Equals(row.Cells["select"].Value, true))
        {
            // get values for selected row
            var mc_no_Value = (string)row.Cells["mc_no"].Value;
            var member_Value = (string)row.Cells["member"].Value;
    
            // do smth with values here
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多