我想获取数据网格视图上一列的详细信息 [英] i want to get the details of a column on data grid view

查看:81
本文介绍了我想获取数据网格视图上一列的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过搜索名称在数据网格视图上获取数据,现在我想通过单击显示名称的单元格来获取相应文本框/标签上该列的详细信息.

我有一个搜索文本框,通过搜索现在可以在datagridview中获取数据,现在我想在标签/textbox上显示与特定人有关的所有记录.

我在datagridview上显示了多条记录,并在文本框中显示了多条记录,因此我希望当用户单击与该人相关的datagridview数据时,应该在texboxes上显示该记录.您可以使用以下代码来获取dataGridView单元格的选定值.

在dataGridView的 CellContentClick 事件上使用此代码.

 {
//  txtbox应该从选定单元格上获取值
txtbox.Text = dataGridView1.SelectedCells [e.selectedCells] .Value.ToString();
} 


事件CellContentClick()可用于识别用户单击了哪个列(单元格).请参见以下示例,

 私有 无效 GridViewUpdataedConstituents_CellContentClick(对象发​​件人,DataGridViewCellEventArgs e)
       {
// 获取所单击的单元格的索引
           iSelectedGridIndex = gridView1.CurrentCell.ColumnIndex;

          // 现在获取点击的单元格的值
          txtSelectedValue.Text = gridView1.CurrentCell.Value.ToString();
} 



事件CellContentClick()属于DataGridView.您只需双击Windows窗体上的任何DataGridView即可获得此事件.


I am getting data on data grid view by searching name and now i want to get the details of that column on respective textboxes/label by clicking on that cell in which name is displayed.

I have got a search text box i got data in the datagridview by searching now i want to display all the records related to the specefic person on the label /textbox.

there are multiple records i am displaying some on datagridview and rest on textboxes so i want when user clicks on the datagridview data related to that person should be display on texboxes

解决方案

You can use below code to get the selected value of the cell of dataGridView.

Use this code on CellContentClick event of the dataGridView.

{
//txtbox should get value from selected cell on
txtbox.Text = dataGridView1.SelectedCells[e.selectedCells].Value.ToString();
} 


The event CellContentClick() can be used to identify which column(cell) is clicked by the user. See the following example,

private void GridViewUpdataedConstituents_CellContentClick(object sender, DataGridViewCellEventArgs e)
       {
//Get the index of the cell clicked
           iSelectedGridIndex = gridView1.CurrentCell.ColumnIndex;

          //Now get the values of the clicked cell 
          txtSelectedValue.Text = gridView1.CurrentCell.Value.ToString();
}



The event CellContentClick() is belongs to DataGridView. You can get this event by simply double click on any DataGridView on Windows form.


这篇关于我想获取数据网格视图上一列的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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