In this post I will show you how you can display row number in datagrid control using IMultiValueConverter.Let us start with the code.The code shown in the List 1 is used to bind using the IMultiValueConverter and the passing parameter for the binding converter are the binding and parent datagrid control
Now in the converter I have simple code to show the row number of the current element which is passed to the converter in first parameter. I have store it in the object type variable. As I don't know what is the type of the first parameter and then I created another parameter of type data grid control and save the second parameter in it. Now in the next statement I have get the Index of the passed parameter in the data grid control and also added 1 in it, as IndexOf will return 0 for the first element. You can see the code in List 2.
And you can see the Row Number column in the Image 1, I have set the header text of the column to "Row Number", You can changed it to you requirements.
In the Image 1 you can see that I have used the left padding for the row number, as you can see that each row number is padded left by 0 I have used it to 2 values, You can also pass the length of your padding in the parameter of the IMultiValueConverter. You can download the source code from here.
All and any comments / bugs / suggestions are welcomed!