如何在asp .net(C#)中获取选定的datagrid列索引 [英] how to get the selected column index of datagrid in asp .net(C#)

查看:62
本文介绍了如何在asp .net(C#)中获取选定的datagrid列索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

我需要从数据网格中获取选定的列索引.我找不到任何Currentcell或SelectedCell,或者我什至无法使用上面建议的e.ColumnIndex.请帮助我.我正在使用Visual Studio2008.

hi...

i need to get the selected column index from the datagrid. i do not find any Currentcell , or SelectedCell or i can not even use e.ColumnIndex as suggested above. please assist me. i am using visual studio 2008.

推荐答案


请点击以下链接:
http://msdn.microsoft.com/en-us/library/x8x9zk5a.aspx [ ^ ]
http: //stackstackflow.com/questions/1135304/selecting-a-row-in-a-datagridview-and-having-the-arrow-on-the-row-header-follow [
Hi,
Follow the links below:
http://msdn.microsoft.com/en-us/library/x8x9zk5a.aspx[^]
http://stackoverflow.com/questions/1135304/selecting-a-row-in-a-datagridview-and-having-the-arrow-on-the-row-header-follow[^]


在DataGridView控件中获取选定的列

使用SelectedColumns属性.若要使用户能够选择列,必须将SelectionMode属性设置为FullColumnSelect或ColumnHeaderSelect.
C#



To get the selected columns in a DataGridView control

Use the SelectedColumns property. To enable users to select columns, you must set the SelectionMode property to FullColumnSelect or ColumnHeaderSelect.
C#



private void selectedColumnsButton_Click(object sender, System.EventArgs e)
  {
      Int32 selectedColumnCount = dataGridView1.Columns
          .GetColumnCount(DataGridViewElementStates.Selected);
      if (selectedColumnCount > 0)
      {
          System.Text.StringBuilder sb = new System.Text.StringBuilder();

          for (int i = 0; i < selectedColumnCount; i++)
          {
              sb.Append("Column: ");
              sb.Append(dataGridView1.SelectedColumns[i].Index
                  .ToString());
              sb.Append(Environment.NewLine);
          }

          sb.Append("Total: " + selectedColumnCount.ToString());
          MessageBox.Show(sb.ToString(), "Selected Columns");
      }
  }




来自MSDN


或尝试这个




From MSDN


or try this

dataGrid.CurrentColumn.DisplayIndex


这篇关于如何在asp .net(C#)中获取选定的datagrid列索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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