Skip to content

Commit 9773afc

Browse files
MSDN-WhiteKnightBillWagner
authored andcommitted
Improve DataGrid.RowHeaderStyle samples (#899)
* Update window1.xaml.cs * Update window1.xaml.vb * Update window1.xaml.vb * Update window1.xaml.cs
1 parent 0abab75 commit 9773afc

File tree

2 files changed

+4
-8
lines changed
  • snippets
    • csharp/VS_Snippets_Wpf/datagrid_rowheader/csharp/datagrid_rowheader
    • visualbasic/VS_Snippets_Wpf/datagrid_rowheader/vb/datagrid_rowheader_vb

2 files changed

+4
-8
lines changed

snippets/csharp/VS_Snippets_Wpf/datagrid_rowheader/csharp/datagrid_rowheader/window1.xaml.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ public object Convert(object value, Type targetType, object parameter, System.Gl
5353
{
5454
try
5555
{
56-
//Get the DataRowView that is being passed to the Converter
57-
System.Data.DataRowView drv = (System.Data.DataRowView)value;
5856
//Get the CollectionView from the DataGrid that is using the converter
5957
DataGrid dg = (DataGrid)Application.Current.MainWindow.FindName("DG1");
6058
CollectionView cv = (CollectionView)dg.Items;
61-
//Get the index of the DataRowView from the CollectionView
62-
int rowindex = cv.IndexOf(drv)+1;
59+
//Get the index of the item from the CollectionView
60+
int rowindex = cv.IndexOf(value)+1;
6361

6462
return rowindex.ToString();
6563
}

snippets/visualbasic/VS_Snippets_Wpf/datagrid_rowheader/vb/datagrid_rowheader_vb/window1.xaml.vb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ Public Class ConvertItemToIndex
2828

2929
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
3030
Try
31-
'Get the DataRowView that is being passed to the Converter
32-
Dim drv As System.Data.DataRowView = DirectCast(value, System.Data.DataRowView)
3331
'Get the CollectionView from the DataGrid that is using the converter
3432
Dim dg As DataGrid = DirectCast(Application.Current.MainWindow.FindName("DG1"), DataGrid)
3533
Dim cv As CollectionView = DirectCast(dg.Items, CollectionView)
36-
'Get the index of the DataRowView from the CollectionView
37-
Dim rowindex As Integer = cv.IndexOf(drv) + 1
34+
'Get the index of the item from the CollectionView
35+
Dim rowindex As Integer = cv.IndexOf(value) + 1
3836

3937
Return rowindex.ToString()
4038

0 commit comments

Comments
 (0)