i have a datagridview that is loading rows from a table from database and there are other columns are filled by a calculation
while filling the datagridview from datatable (ex.30 rows ) and then calculate the other column it takes more than 50 sec
i don't know this delay with this small number :(
can anyone help
Private Sub loadDetails(proc_id As String, proc_type As Integer)
If OraxCon.State = ConnectionState.Open Then OraxCon.Close()
Dim sqlstr As String = "select * from Inv_Sub where proc_id=" & proc_id & " and proc_type=2"
OraxCon.Open()
sda = New SqlDataAdapter(sqlstr, OraxCon)
dt = New DataTable()
sda.Fill(dt)
inv_subDataGridView.Columns("item_name").AutoSizeMode = DataGridViewAutoSizeColumnMode.None
If dt.Rows.Count = 0 Then
'' isexited = False
Return
Else 'empty dgv
For Each row As DataGridViewRow In inv_subDataGridView.Rows
For Each cell As DataGridViewCell In row.Cells
cell.Value = ""
Next
Next
End If
If dt.Rows.Count > 0 Then
ISLOADEDINV = True
Dim rows_diff As Integer = 0
Try
If dt.Rows.Count > inv_subDataGridView.Rows.Count Then
rows_diff = dt.Rows.Count - inv_subDataGridView.Rows.Count
End If
For j As Integer = 1 To rows_diff
inv_subDataGridView.Rows.Add()
Next
Catch
End Try
ReDim Preserve Unit_Perc(dt.Rows.Count)
For i As Integer = 0 To dt.Rows.Count - 1
Dim cr = New Currencies(Int32.Parse(dt.Rows(i).Item("currency_from").ToString()))
If cr.isexited = True Then
inv_subDataGridView.Rows(i).Cells("id").Value = cr.id
inv_subDataGridView.Rows(i).Cells("temp_id_barcode").Value = cr.id
inv_subDataGridView.Rows(i).Cells("barcode").Value = cr.barcode.ToString()
inv_subDataGridView.Rows(i).Cells("item_name").Value = cr.symbol
inv_subDataGridView.Rows(i).Cells("unit").Value = dt.Rows(i).Item("unit").ToString()
inv_subDataGridView.Rows(i).Cells("unitname").Value = cr.get_unitname(Int32.Parse(dt.Rows(i).Item("unit").ToString()))
If dt.Rows(i).Item("val").ToString() = dt.Rows(i).Item("val1").ToString() Then
inv_subDataGridView.Rows(i).Cells("quantity").Value = dt.Rows(i).Item("val").ToString()
Else
Unit_Perc(i) = dt.Rows(i).Item("val") / dt.Rows(i).Item("val1")
inv_subDataGridView.Rows(i).Cells("quantity").Value = dt.Rows(i).Item("val1")
End If
sett.userpermission(user_IDLabel.Text, 10004)
If sett.costWithVat = 1 Then
inv_subDataGridView.Rows(i).Cells("price").Value = dt.Rows(i).Item("new_exchange_price").ToString()
inv_subDataGridView.Rows(i).Cells("taxval").Value = dt.Rows(i).Item("new_taxval").ToString()
Else
inv_subDataGridView.Rows(i).Cells("taxval").Value = dt.Rows(i).Item("taxval").ToString()
inv_subDataGridView.Rows(i).Cells("price").Value = dt.Rows(i).Item("exchange_price").ToString()
End If
inv_subDataGridView.Rows(i).Cells("discount").Value = dt.Rows(i).Item("discount").ToString()
inv_subDataGridView.Rows(i).Cells("taxperc").Value = dt.Rows(i).Item("taxperc").ToString()
Try
inv_subDataGridView.Rows(i).Cells("total").Value = Double.Parse(inv_subDataGridView.Rows(i).Cells("price").Value.ToString()) * Double.Parse(inv_subDataGridView.Rows(i).Cells("quantity").Value.ToString())
inv_subDataGridView.Rows(i).Cells("totalafterdiscount").Value = Double.Parse(inv_subDataGridView.Rows(i).Cells("total").Value.ToString()) - Double.Parse(inv_subDataGridView.Rows(i).Cells("discount").Value.ToString())
If sett.costWithVat = 1 Then
inv_subDataGridView.Rows(i).Cells("nettotal").Value = Double.Parse(inv_subDataGridView.Rows(i).Cells("totalafterdiscount").Value.ToString()) '' + Double.Parse(inv_subDataGridView.Rows(i).Cells("taxval").Value.ToString())
Else
inv_subDataGridView.Rows(i).Cells("nettotal").Value = Double.Parse(inv_subDataGridView.Rows(i).Cells("totalafterdiscount").Value.ToString()) + Double.Parse(inv_subDataGridView.Rows(i).Cells("taxval").Value.ToString())
End If
Catch
End Try
Try
inv_subDataGridView.CurrentCell = inv_subDataGridView.Rows(i + 1).Cells("barcode") 'temp_id_barcode
Catch
End Try
End If
Next
End If
inv_subDataGridView.EndEdit(True)
inv_subDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit)
Try
inv_subDataGridView.Columns("item_name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
Catch
End Try
ISLOADEDINV = Falsei tried autoresizing and doublebuffer and stopdrawing but it still sooo slow
SendMessage(ItemSrchDGV.Handle, WM_SETREDRAW, False, 0)i spent a week solving the prob and no use
please help
big thanx