用户单击GridView标头时如​​何获取列名或索引 [英] how to get column name or index when user click on gridview header

查看:216
本文介绍了用户单击GridView标头时如​​何获取列名或索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击gridview标头时,可以获取列索引或名称
带vb.net的asp.net

when User click on gridview header so can one get column index or name
asp.net with vb.net

推荐答案

如果在单击列标题时问题需要知道列的索引和名称,则使用Window Form的答案(VB.Net)将通过符合事件签名的方法来处理ColumnHeaderMouseClick事件(请参见示例).

例如.假设DataGridView控制项是DataGridView1
私有子HeaderClick(按对象发送ByByVal,按System.Windows.Forms.DataGridViewCellMouseEventArgs处理ByVal e)处理DataGridView1.ColumnHeaderMouseClick
昏暗的col_index = e.ColumnIndex
昏暗的col_name = DataGridView1.Columns(col_index).Name
MessageBox.Show(String.Format("Index = {0},Name = {1}",col_index,
col_name))
结束Sub
If the question need to know the index and name of a column when its column header was clicked, then the answer for Window Form (VB.Net) is to handle the event ColumnHeaderMouseClick by a method which conform the event signature (seen the example).

Eg. Suppose that the DataGridView contol is DataGridView1
Private Sub HeaderClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
Dim col_index = e.ColumnIndex
Dim col_name = DataGridView1.Columns(col_index).Name
MessageBox.Show(String.Format("Index={0}, Name={1}", col_index,
col_name))
End Sub


这篇关于用户单击GridView标头时如​​何获取列名或索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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