如何从选定的数据网格视图项中获取值 [英] How Can I Get A Value From Selected Data Grid View Item

查看:98
本文介绍了如何从选定的数据网格视图项中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个4列的datagrig视图
例如,名称,添加,Dob和带有复选框的第4列
现在,当我加载多个值时,我只想保存选定的行值,即我在其中单击复选框的行.

解决方案

请参阅以下链接,了解类似问题

从datagridview的选定行中获取价值 [ ^ ]

如果该复选框列已绑定,则可以获取其值(以及其他列的值)并保存.如果它在模板列中,则应先找到复选框控件,然后获取其值.


您可以在datagridview中使用CellContentClick event

 私有 无效 grdFclick_CellContentClick(对象发​​件人,DataGridViewCellEventArgs e)
{
    if ( bool  .Parse(grdFclick.Rows [e.RowIndex] .Cells [字符串 val = grdFclick.Rows [e.RowIndex] .Cells [ 1 ].Value.ToString() ;
     }
} 


I got a datagrig view with 4 columns
eg,Name,Add,Dob and 4th column with checkbox
now when i load multiple values it it i want to save only selected rows value i.e row ehere i click on checkbox.

解决方案

Please see below link for similar issue

get value from selected rows in datagridview[^]


If the checkbox column is bound you can get its value (and of the other columns) and save it. If its in a templatecolumn you should find the checkbox control first and then get its value.


you can use CellContentClick event in datagridview

private void grdFclick_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
   if(bool.Parse(grdFclick.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()))
     {

        string val = grdFclick.Rows[e.RowIndex].Cells[1].Value.ToString();
     }
}


这篇关于如何从选定的数据网格视图项中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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