CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2002
    Location
    Mumbai
    Posts
    98

    Smile Datagrid Row heading

    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
    Last edited by AmitInnani; June 27th, 2005 at 04:35 AM.

  2. #2
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Datagrid How heading

    DataGridColumnStyle.HeaderText property is what you are looking for.

    This is taken from MSDN:
    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
    (If I helped you, Rate ThisPost is much appreciated)

  3. #3
    Join Date
    Sep 2002
    Location
    Mumbai
    Posts
    98

    Smile Re: Datagrid How heading

    Thanks

    But this will set the column heading, I want to set the Row Heading i,e Fixed column on Left Hand Side.

  4. #4
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Datagrid How heading

    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)

  5. #5
    Join Date
    Sep 2002
    Location
    Mumbai
    Posts
    98

    Re: Datagrid Row heading

    Thanks it worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured