选中复选框时,获取datagrid列的值. [英] get values of a datagrid column when checkbox is checked.

查看:210
本文介绍了选中复选框时,获取datagrid列的值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从一个网格视图得到一个列的值时复选框被选中.

请任何人帮助我.

How can I get the value of a column from a grid view when check box is checked.

Please any one help me.

推荐答案


首先,您需要对复选框的"Click"事件做出反应.
你知道你怎么做吗?

然后,我将使用DataGridView类中的 Row Columns 方法.


也许也尝试这样的事情:
Hi,
first of all you need to react on the "Click" Event of your check box.
You know how you do?

Then I would use Row and Columns methods from DataGridView class.


Maybe also try something like this:
<pre lang="midl">dataGridView->Rows[ myRow ]->Cells[ myCell ]->Value</pre><br />


获得某个单元格的值.在C#中使用


to get the value of a certain cell. In C# use

<pre lang="midl">dataGridView.Rows[ myRow ].Cells[ myCell ].Value</pre><br />




另请参见:
http://msdn.microsoft.com /en-en/library/system.windows.forms.datagridview.rows(v=VS.80).aspx [ http://msdn.microsoft.com /de-de/library/system.windows.forms.datagridview.columns(v=VS.80).aspx [




See also:
http://msdn.microsoft.com/en-en/library/system.windows.forms.datagridview.rows(v=VS.80).aspx[^]

and

http://msdn.microsoft.com/de-de/library/system.windows.forms.datagridview.columns(v=VS.80).aspx[^]


int id;
for (int i = 0; i < grdDisplayAll.Rows.Count; i++)
{
  //Assume that 0th Row of grid named grdDisplayAll contains Checkbox
  if (Convert.ToBoolean(grdDisplayAll.Rows[i].Cells[0].Value) == true)
  {
    id = grdDisplayAll.Rows[i].Cells["Id"].Value;
    //You may use columnIndex of column instead of ColumnName (i.e. Here "Id")

    //Code here to make whatever you want to perform on selected record
  }
}


:)
如果对您有帮助,请标记为答案.;)


:)
Mark as Answer if it is helpful to you.. ;)


for(int i = 0; i& lt; grvTableNames.RowCount-1; i ++ )
{
如果(Convert.ToBoolean(grvTableNames.Rows [i] .Cells [0] .EditedFormattedValue))
{
字符串tableName = dataTable.Rows [i] [alias] .ToString();
wordDataTable = businessLogic.GetTableAttibutes(name,tableName);
wordDataTable.TableName = tableName;
ds.Tables.Add(wordDataTable);
}
}


希望对您有帮助.
for (int i = 0; i &lt; grvTableNames.RowCount - 1; i++)
{
if (Convert.ToBoolean(grvTableNames.Rows[i].Cells[0].EditedFormattedValue))
{
string tableName = dataTable.Rows[i][alias].ToString();
wordDataTable = businessLogic.GetTableAttibutes(name, tableName);
wordDataTable.TableName = tableName;
ds.Tables.Add(wordDataTable);
}
}


Hope this will be helpful for you.


这篇关于选中复选框时,获取datagrid列的值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆