[英]How to get the GridView selected Column index
i am trying to get the Gridview selected column index from wpf program. 我试图从WPF程序中获取Gridview选定的列索引。 i can get the selected row index but not the selected colum index
我可以获取所选的行索引,但不能获取所选的列索引
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string lbl_nam = (Label)GridView1.Rows[GridView1.SelectedIndex].FindControl("Label_nam");
string nam = lbl_nam.Text;
}
If you are in a position to change GridView
control to DataGrid
, you can try the code given below to get the current column's display index of the DataGrid
from code behind: 如果您可以将
GridView
控件更改为DataGrid
,则可以尝试下面给出的代码,以从后面的代码获取DataGrid
当前列的显示索引:
dataGrid.CurrentColumn.DisplayIndex
dataGrid.CurrentColumn.DisplayIndex
This CurrentColumn.DisplayIndex
property of DataGrid basically gets or sets the display order of the column relative to the currently displayed columns. DataGrid的
CurrentColumn.DisplayIndex
属性基本上获取或设置列相对于当前显示的列的显示顺序。 It provides you the zero-based position of the column as it is displayed in the associated DataGridView, or -1 if the band is not contained within a control. 它提供了列在相关联的DataGridView中显示的从零开始的位置,或者如果控件中不包含该范围,则返回-1。
Hope the information will be helpful for you .. 希望这些信息对您有帮助。
Regards 问候
Debasis 德巴斯
This is how we can get the value of a specific cell 这就是我们如何获取特定单元格的值
Object obj = GetCell(3).Content;
string cellContent = String.Empty;
if (obj != null)
{
if (obj is TextBox)
cellContent = ((TextBox)(obj)).Text;
else
cellContent = ((TextBlock)(obj)).Text;
}
private DataGridCell GetCell(int column)
{
DataGridRow rowContainer = GetRow();
if (rowContainer != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
// Try to get the cell but it may possibly be virtualized.
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
if (cell == null)
{
// Now try to bring into view and retreive the cell.
customDataGrid.UCdataGridView.ScrollIntoView(rowContainer, customDataGrid.UCdataGridView.Columns[column]);
cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
}
return cell;
}
return null;
}
i hope it will helps you.... 我希望它将对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.