I'm learning WPF MVVM pattern. I'm stuck in Binding CurrentCell
of datagrid
. Basically I need the row index and column index of current cell.
<DataGrid AutoGenerateColumns="True"
SelectionUnit="Cell"
CanUserDeleteRows="True"
ItemsSource="{Binding Results}"
CurrentCell="{Binding CellInfo}"
Height="282"
HorizontalAlignment="Left"
Margin="12,88,0,0"
Name="dataGrid1"
VerticalAlignment="Top"
Width="558"
SelectionMode="Single">
Here is my ViewModel
private User procedureName = new User();
public DataGridCell CellInfo
{
get { return procedureName.CellInfo; }
//set
//{
// procedureName.CellInfo = value;
// OnPropertyChanged("CellInfo");
//}
}
Here is my Model
private DataGridCell cellInfo;
public DataGridCell CellInfo
{
get { return cellInfo; }
//set
//{
// cellInfo = value;
// OnPropertyChanged("CellInfo");
//}
}
And in my ViewModel CellInfo
is always null
. I am not able to get the value from the currentcell
in datagrid
. Please let me know a way to getCurrentCell
in the ViewModel.
if (CellInfo != null)
{
MessageBox.Show("Value is" + CellInfo.Column.DisplayIndex.ToString());
}