简体   繁体   English

如何使用C#在Windows窗体的数据网格视图中获取所选列的索引?

[英]How to get the index of the selected column in data grid view in windows forms using c#?

How to get the index of the selected column in DataGridView ? 如何获取DataGridView中选定列的索引? (windows forms using c#) (使用C#的Windows窗体)

I have a DataGridView with 30 columns in it.Now the task is,when the user clicks any of the 30 columns header,the selected column index is shown in message box.I want help to do this.. 我有一个包含30列的DataGridView。现在的任务是,当用户单击30列标题中的任何一个时,所选的列索引将显示在消息框中。我需要帮助。

write your code in ColumnHeaderMouseClick 在ColumnHeaderMouseClick中编写代码

   private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        MessageBox.Show(e.ColumnIndex.ToString());
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM