Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 DataGridView is laggy for 100 cols X 100 rows and how to resize the header text?

$
0
0
Hi guys, I have a datagridview in my application where it will has 100 rows and 100 cols and these are created during runtime. There is a column header and row header each with numeric as text and it starts with 1 to 100. Parts of the cells are filled with BackColor = Blue and whenever the user select a particular cell, the cell's backcolor will be changed to white and the color will be toggle back to blue if the user click the cell again. Also, I'm displaying the selected cell column index and row index on labels. No values in all cells and just the backcolor only.

My 1st problem is, the datagridview is lag when the user select the cell, it needs to wait for few seconds before the backcolor got changed and the delay is caused by changing the backcolor call.
May i know is there anyway to optimize the code below to fix the lagging?


My second question is how to resize the header text so that it will fit within the resized header? For the code below, I'm using a fixed font size for testing purpose and pelase advise what would be the correct way to resize the font size of the header text?

Code:
Code:


Private Sub CellGridInit()
        Dim i As Integer
        Dim b As Integer

        '##### WAFER GRID SETTINGS ######
        With CellGrid
            .Rows.Clear()
            .Columns.Clear()
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False
            .AllowUserToAddRows = False
            .AllowUserToDeleteRows = False
            .AllowUserToOrderColumns = False
            .ReadOnly = True
            .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .ClearSelection()
        End With

        '###### COLUMN SETTINGS ########
        CellGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
        CellGrid.ColumnHeadersDefaultCellStyle.Font = New System.Drawing.Font("Microsoft Sans Serif", 5.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        CellGrid.ColumnCount = 100
        For b = 0 To 99
            CellGrid.Columns(b).HeaderText = b + 1
        Next

        '##### ROW SETTINGS ######
        CellGrid.RowHeadersWidth = CInt(CellGrid.RowHeadersWidth * 1.35)
        CellGrid.RowTemplate.Height = CInt((CellGrid.Height - CellGrid.ColumnHeadersHeight * 2) / 100)
        CellGrid.AllowUserToAddRows = False
        CellGrid.RowHeadersDefaultCellStyle.Font = New System.Drawing.Font("Microsoft Sans Serif", 5.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

        For i = 0 To 99
            CellGrid.Rows.Add()
                CellGrid.Rows(i).HeaderCell.Value = i + 1
            End If
        Next

        '##### Clear selection #####
        CellGrid.ClearSelection()
 End Sub


Private Sub CellGrid_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles CellGrid.CellClick
   
        lblBar.Text = e.ColumnIndex
        lblDevice.Text = e.RowIndex

            If CellGrid.Item(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Blue Then          'Selected
                CellGrid.Item(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.White              'De-select
               
            ElseIf CellGrid.Item(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.White Then      'De-selected
                CellGrid.Item(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Blue              'Selects
            End If
            CellGrid.ClearSelection()

    End Sub


Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>