私はwpfプログラムからGridview選択列インデックスを取得しようとしています。選択された行インデックスは取得できますが、選択された列インデックスは取得できません
GridView
コントロールを DataGrid
に変更する場合は、以下のコードを試して、 DataGrid
の現在の列の表示インデックスを取得できます>コードの背後から:
dataGrid.CurrentColumn.DisplayIndex
DataGridのこの CurrentColumn.DisplayIndex
プロパティは、基本的に現在表示されている列を基準にした列の表示順序を取得または設定します。これは、関連付けられたDataGridViewに表示される列のゼロベースの位置を提供します。バンドがコントロール内に含まれていない場合は、-1を返します。
情報があなたに役立つことを願っています..
よろしく
デバシス
これは、特定の細胞の値を取得する方法です
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(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;
}
それがあなたを助けることを願っています....