我正在尝试从wpf程序中获取Gridview选择列索引。我可以获得选定的行索引,但不能获得选定的列索引
答案 0 :(得分:0)
如果您可以将GridView
控件更改为DataGrid
,则可以尝试使用下面给出的代码从后面的代码中获取当前列的DataGrid
的显示索引:< / p>
dataGrid.CurrentColumn.DisplayIndex
DataGrid的此CurrentColumn.DisplayIndex
属性基本上获取或设置列相对于当前显示列的显示顺序。它为相关DataGridView中显示的列提供了从零开始的位置,如果控件中未包含该带,则为-1。
希望这些信息对您有所帮助..
此致
Debasis
答案 1 :(得分:0)
这就是我们如何获得特定细胞的价值
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;
}
我希望它会帮助你......
答案 2 :(得分:0)
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string lbl_nam = (Label)GridView1.Rows[GridView1.SelectedIndex].FindControl("Label_nam");
string nam = lbl_nam.Text;
}