How do i return the column index of an item within a WPF Datagrid, when I click on a cell I'm using Visual Studio 2010/VB.Net
相关问题
- VNC control for WPF application
- 'System.Threading.ThreadAbortException' in
- how to use special characters like '<'
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
DataGridCells
do not have a Click event, they have aSelected
event but that is normally fired for each cell in a row when you click on a cell.GotFocus
might be a better choice.e.g.
and:
DataGridCell.Column.DisplayIndex
seems to return an appropriate index, if it somehow is not enough you can useDataGrid.Columns.IndexOf(DataGridCell.Column)
.You can use below code directly to get selected cells column index.
Every Body Is tells about this solution
and yes it works but nobody tells that we have to set Display index first fro every column, may be it is quiet obvious for Experts to get that, but for novices it's unfamiliar thing
There are two ways to set it :-
1) You can set it in XAML part..
i don't know how to set it for custom columns like
so I preferred the other Way
2) Created A function
dt
is my Data Tableand I am assigning Display Indexes to it
Now if you use
then You will surely Get the Index
You tried use this at the Event Click for Column Index?
I'm using this code in MouseDoubleClick Event or PreviewKeyUp and works perfectly.