Hi,
We have updated our application from VB 6 to VB.Net. We are using VS 2008. Now we are trying to convert MSFlexgrid used in our application to DataGridView. Here is my datagridview code
Try Dim i As Integer Dim j As Integer Dim txtToAppend As String = "" Dim dstime As New DataSet Dim sqlcmd As DbCommand Dim rowcnt As Integer = InputBox("Please Enter RowCount", "DataSource") txtToAppend = DateAndTime.Timer Debug.Print(DateAndTime.Timer) sqlcmd = CommonObj.CommandObj(True) sqlcmd.Connection = getcon("Collections_Closed") sqlcmd.CommandText = "select top(" & rowcnt & ") * from collections" adapter.SelectCommand = sqlcmd adapter.Fill(dstime, "Collections") With DtdgDataSource .SuspendLayout() .DataSource = Nothing .AllowUserToAddRows = False .AllowUserToDeleteRows = False .AllowUserToResizeRows = False .AllowUserToOrderColumns = True .SelectionMode = DataGridViewSelectionMode.FullRowSelect .ReadOnly = True .MultiSelect = False .RowHeadersVisible = False .Columns.Clear() .Rows.Clear() .VirtualMode = True End With DtdgDataSource.GetType.InvokeMember("DoubleBuffered", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.SetProperty, Nothing, DtdgDataSource, New Object() {True}) DtdgDataSource.DataSource = dstime.Tables("Collections") For i = 0 To (rowcnt / 2) DtdgDataSource.Rows(i).DefaultCellStyle.BackColor = Color.LemonChiffon Next For i = 0 To DtdgDataSource.RowCount - 2 For j = 2 To 7 DtdgDataSource.Rows(i).Cells(j).Style.ForeColor = Color.DarkOrange Next Next For i = 0 To DtdgDataSource.RowCount - 2 For j = 8 To 13 DtdgDataSource.Rows(i).Cells(j).Style.Font = New Font(DtdgDataSource.Font, FontStyle.Bold) Next Next Catch ex As Exception MsgBox(Err.Description & vbTab & "Button3_Click") End Try
We are testing speed of both controls and we noticed that DataGridView is very much slow than MSFlexgrid while formatting cells(Changing background and foreground colour, making text bold etc).Its hard to use DataGridView if it is much slow. Why is DataGridView is slow while formatting? Is there any way to speed up?
Thank you