Can we set the RowHeading to datagrid rows?
If Yes, kindly help me in how to do it or how to freeze the first column of the grid.
Or how can we freeze the column of the datagrid?
Thanks :wave:
Printable View
Can we set the RowHeading to datagrid rows?
If Yes, kindly help me in how to do it or how to freeze the first column of the grid.
Or how can we freeze the column of the datagrid?
Thanks :wave:
DataGridColumnStyle.HeaderText property is what you are looking for.
This is taken from MSDN:
(If I helped you, Rate ThisPost is much appreciated)Code:Private Sub SetHeaderText()
Dim dgCol As DataGridColumnStyle
Dim dataCol1 As DataColumn
Dim dataTable1 As DataTable
dgCol = dataGrid1.TableStyles(0).GridColumnStyles(0)
dataTable1 = dataSet1.Tables(dataGrid1.DataMember)
dataCol1 = dataTable1.Columns(dgCol.MappingName)
dgCol.HeaderText = dataCol1.Caption
End Sub 'SetHeaderText
Thanks
But this will set the column heading, I want to set the Row Heading i,e Fixed column on Left Hand Side.
I didn't understand what you need.
Here is an example of how to put the row number in the Grid row. You will need to inherit from the DataGrid and implement the OnPaint method:
Code:Private Sub MyGrid_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Try
Dim row As Integer = 0
Dim yDelta As Integer = GetCellBounds(row, 0).Height + 1
Dim y As Integer = GetCellBounds(row, 0).Top + 2
Dim cm As CurrencyManager = CType(BindingContext(DataSource, DataMember), CurrencyManager) '
While ((y < Height - yDelta) And (row < cm.Count))
Dim text As String = String.Format("{0}", row + 1)
e.Graphics.DrawString(text, Me.Font, New SolidBrush(Color.Black), 12, y)
y += yDelta
row += 1
End While
Catch ex As Exception
Finally
End Try
End Sub
(If I helped you, Rate This Post is much appriciated)
Thanks it worked. :wave: