|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
refresh performance in datagrid - big problemI have a problem with the refresh performance in datagrid – when datagrid is being shown it is so slow that I can see one by one cells is drawn -datagrid contains about 35x40 of cells - they are generated through the odswierz_frekfencje() function (listed below)- -other datagrid – showing data from datasets are ok -I suppose I have made some mistakes, could you give me a hint? which? Sorry for crosspost! Public Sub odswierz_frekfencje() If status = True Then ' Me.DataGridView1.BeginEdit(False) Dim miesiac, rok, liczba_dni As Integer miesiac = Me.DateTimePicker1.Value.Month rok = Me.DateTimePicker1.Value.Year If miesiac = 1 Or miesiac = 3 Or miesiac = 5 Or miesiac = 7 Or miesiac = 8 Or miesiac = 10 Or miesiac = 12 Then liczba_dni = 31 End If If miesiac = 4 Or miesiac = 6 Or miesiac = 9 Or miesiac = 11 Then liczba_dni = 30 End If If miesiac = 2 And rok / 4 <> Math.Floor(rok / 4) Then liczba_dni = 28 End If If miesiac = 2 And rok / 4 = Math.Floor(rok / 4) Then liczba_dni = 29 End If Dim id_klasy, id_ucznia, i, j, liczba_ocen As Integer 'Dim pozycje() = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} Dim buttonColumn As New DataGridViewButtonColumn With buttonColumn .HeaderText = "Dodaj:" .Name = "dodaj" .Text = "Dodaj:" ' Use the Text property for the button text for all cells rather ' than using each cell's value as the text for its own button. .UseColumnTextForButtonValue = True End With id_klasy = klasa.SelectedValue.row.id_klasy With DataGridView1 .Rows.Clear() .Columns.Clear() .Columns.Add("nr_dziennik", "Numer w dzienniku") .Columns("nr_dziennik").DefaultCellStyle.Font = New Font("Courier", 12, FontStyle.Bold, GraphicsUnit.Pixel) .Columns("nr_dziennik").Width = 50 .Columns("nr_dziennik").AutoSizeMode = DataGridViewAutoSizeColumnMode.None .Columns("nr_dziennik").SortMode = DataGridViewColumnSortMode.NotSortable .Columns.Add("uczen", "uczen") .Columns("uczen").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells .Columns("uczen").DefaultCellStyle.Font = New Font("Verdana", 12, FontStyle.Underline, GraphicsUnit.Pixel) .Columns("uczen").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft .Columns("uczen").SortMode = DataGridViewColumnSortMode.NotSortable .Columns.Add("id_ucznia", "id ucznia") .Columns("id_ucznia").Visible = False .Columns("id_ucznia").SortMode = DataGridViewColumnSortMode.NotSortable .Columns.Add("id_klasy", "id klasy") .Columns("id_klasy").Visible = False .Columns("id_klasy").SortMode = DataGridViewColumnSortMode.NotSortable .Columns.Add(buttonColumn) .Columns("dodaj").Visible = False .Columns("dodaj").SortMode = DataGridViewColumnSortMode.NotSortable .Rows.Add() .Rows(0).Cells(0).ReadOnly = True .Rows(0).Cells(1).ReadOnly = True .Rows(0).Cells(2).ReadOnly = True .Rows(0).Cells(3).ReadOnly = True For j = 1 To liczba_dni .Columns.Add(Str(j), Str(j)) .Columns(Str(j)).Width = 28 .Columns(Str(j)).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns(Str(j)).SortMode = DataGridViewColumnSortMode.NotSortable .Rows(0).Cells(j + 4).Style.BackColor = My.Settings.Item("dtyg_B_" + Trim(Str(Weekday(Str(miesiac) + "/" + Str(j) + "/" + Str(rok))))) .Rows(0).Cells(j + 4).Style.ForeColor = My.Settings.Item("dtyg_F_" + Trim(Str(Weekday(Str(miesiac) + "/" + Str(j) + "/" + Str(rok))))) .Rows(0).Cells(j + 4).Value = My.Settings.Item("dtyg_" + Trim(Str(Weekday(Str(miesiac) + "/" + Str(j) + "/" + Str(rok))))) Next End With vuczniowieBindingSource.Filter = "id_klasy='" + Str(id_klasy) + "'" vuczniowieBindingSource.Sort = "nr_dziennik" liczba_ocen = 0 Try Me.Pobierz_frekfencjeTableAdapter.Fill(Me.Blizej_szkolyDataSet.pobierz_frekfencje, New System.Nullable(Of Integer)(CType(id_klasy, Integer)), New System.Nullable(Of Integer)(CType(miesiac, Integer)), New System.Nullable(Of Integer)(CType(rok, Integer))) Catch ex As System.Exception blad.pokaz(ex.Message) End Try For i = 0 To vuczniowieBindingSource.Count - 1 id_ucznia = vuczniowieBindingSource.Item(i).row.id_ucznia With DataGridView1 .Rows.Add() .Rows(i + 1).Cells(0).Value = vuczniowieBindingSource.Item(i).row.nr_dziennik .Rows(i + 1).Cells(1).Value = vuczniowieBindingSource.Item(i).row.uczen .Rows(i + 1).Cells(2).Value = id_ucznia .Rows(i + 1).Cells(3).Value = id_klasy End With 'MsgBox(Pobierz_ocenyBindingSource.Count) Me.frekfencjaBindingSource1.Filter = "id_ucznia='" + Str(id_ucznia) + "'" For j = 0 To Me.frekfencjaBindingSource1.Count - 1 With frekfencjaBindingSource1.Item(j).row If .spoznienie = True Then DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Value = "S" If .status > 0 Then DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Style.BackColor = My.Settings.frek_spoznienie_poszlo Else DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Style.BackColor = My.Settings.frek_spoznienie End If Else If .ilosc_godzin > 0 Then Try DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Value += .ilosc_godzin Catch ex As Exception DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Value = .ilosc_godzin End Try Else DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Value = "X" End If If .usprawiedliwiona = True Then If .status > 0 Then DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Style.BackColor = My.Settings.frek_nobecny_poszlo Else DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Style.BackColor = My.Settings.frek_nobecny End If Else If .status > 0 Then DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Style.BackColor = My.Settings.frek_nnobecny_poszlo Else DataGridView1.Rows(i + 1).Cells(.liczba_dni + 4).Style.BackColor = My.Settings.frek_nnobecny End If End If End If End With Next Next id_ucznia = -1 Try Me.Pobierz_frekfencje_txtTableAdapter.Fill(Me.Blizej_szkolyDataSet.pobierz_frekfencje_txt, New System.Nullable(Of Integer)(CType(id_ucznia, Integer)), miesiac, rok) Catch ex As System.Exception blad.pokaz(ex.Message) End Try Me.DataGridView1.Visible = True End If End Sub Hi,
Thanks for your post! I have copied your code snippet and pasted in a new winform project. After performing some formatting task and add several controls based on guess, there are still much thing unclear in the code snippet, and it can not compile. Anyway, I will try my test to give it an analysis and provide some information to you. Can you tell me when does the code be execute? I assume it is called in Form.Load event. After performing some review with your code snippet, I found that you are not doing databinding with the DataGridView, instead, you populate the Cells manually with code. I am not sure if this is the root cause, however, it may have some performance penalty. Can you tell me why you do not want to use databinding with DataGridView? If performance is a concern in DataGridView, Virtual-mode can be used to achieve the best performance. For more information, please refer to the guideline below: "Performance Tuning in the Windows Forms DataGridView Control" http://msdn2.microsoft.com/en-us/library/ms171621.aspx For testing's sake, I recommend you fill the DataSet and use databinding to display it in the DataGridView, is the performance still poor? At last, if you still can not improve the performance with the suggestion I provided above, is it possible for you to provide a little sample project to demonstrate the performance problem? You'd better get rid of the Database dependency and construct the data with code. This will be more efficiency for us to troubleshoot the issue. Thanks. Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Hi,
Have you reviewed my reply? Is your problem resolved? Please feel free to tell me, thanks! Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Jeffrey Tan[MSFT] napisał(a):
> Hi, The problem still exist, I have founded that when I set property visible > > Have you reviewed my reply? Is your problem resolved? Please feel free to > tell me, thanks! to false and after that to true the datagrid isn’t presented at once but I can see that it is build field by field – it takes about 1 sec but for example Microsoft Excell works faster even the every field is computed. I will prepare complete ready to compile source code and in this way I will present it to you, but I have to have some time for it. Hi,
Thanks for your feedback. Yes, I understand the DataGridView cell paiting performance behavior you described, I agree that this performance is not a normal behavior which may be caused by improper coding. However, without reproducing this behavior, it is hard for us to find out the root cause or provide a solution. It may requires some intensive debugging with it. So I will wait for your effort regarding creating a little sample project. Thanks for your understanding. Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Hi,
Have you managed to create a sample project? How about your problem? Please feel free to feedback the post state. Thanks. Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Barcode Reader
Form_Keydown being overridden circular left shift in VB Sending a command to a COM port... Collection? Application KeepAlive? How to get checkedlistbox to display horizontal Help! have no idea what this is about! No symbols are loaded for any call stack frame ... Servlet Counterpart in VB.NET MouseHover doesn't work? |
|||||||||||||||||||||||