Dear Wisej!
My problem is simple. I have a panel, and i want to load custom created usercontrols to it fast, but I can’t get it working.
Here is my code so far:
Private _LoadThread As Threading.Thread
Friend Sub ReloadDatagrid()
_LoadThread = New Threading.Thread(AddressOf ReloadDatagridAsync)
_LoadThread.Start()
End Sub
Private Sub ReloadDatagridAsync()
Application.Update(Me, Sub()
ShowLoader = True
PanelMain.Controls.Clear()
FlowLayoutPanelFlairs.Controls.Clear()
End Sub)
If CurrentSQLParams Is Nothing Then
CurrentSQLParams = New List(Of SQLParam)
SQLMuvelet.AddInSQLParam(CurrentSQLParams, “@UserName”, SqlDbType.VarChar, ParentPageFront.UserName)
End If
Dim SqlKapcsolat1 As New SqlConnection
SQLMuvelet.KapcsolatBeallitas(SqlKapcsolat1)
Dim ReturnValues1 As New DataTable
Try
SQLMuvelet.ExecStoredProc(CurrentSQLParams, “pView_Projects”, SqlKapcsolat1, ReturnValues1)
Catch ex As Exception
MsgBox(“Szerver oldali hiba!” & vbNewLine & “Csatlakozva vagy a hálózathoz?”, vbCritical, “Hiba!”)
ParentPageFront.ErrorHandler.WriteLog(ex)
Exit Sub
End Try
FilterFlairs = New List(Of FlairCard)
Dim listToAdd As New List(Of ProjectStrip)
For Each r As DataRow In ReturnValues1.Rows
Dim pc As New ProjectStrip() With
{.ParentPageFront = ParentPageFront,
.ProjectID = r.Item(“ProjectID”).ToString,
.ProjectRefrenceID = r.Item(“ProjectReferenceNumber”).ToString,
.ProjectName = r.Item(“ProjectName”).ToString,
.ProjectCompany = r.Item(“CompanyName”).ToString,
.ProjectStatus = r.Item(“ProjectStatus”).ToString,
.RemainingTasks = r.Item(“ProjectActiveTaskCount”).ToString,
.DaysLeft = r.Item(“ProjectDaysLeft”).ToString,
.Dock = DockStyle.Top,
.Margin = New Padding(5)}
listToAdd.Add(pc)
Next
listToAdd.Reverse()
Application.Update(Me, Sub()
PanelMain.Controls.AddRange(listToAdd.ToArray)
DisplayCount()
End Sub)
listToAdd.Reverse()
Application.Update(Me, Sub()
For Each control As ProjectStrip In listToAdd
control.LoadAll()
Next
ShowLoader = False
End Sub)
End Sub
Inside the ProjectStrip class there is a “LoadAll” like this:
Public Sub LoadAll()
LoadFlairs()
LoadUsers()
LoadTasks()
End Sub
Public Sub LoadFlairs()
FlowLayoutPanelFlairs.ShowLoader = True
FlowLayoutPanelFlairs.Controls.Clear()
Flairs.Clear()
Dim SqlKapcsolat1 As New SqlConnection
SQLMuvelet.KapcsolatBeallitas(SqlKapcsolat1)
Dim ReturnValues1 As New DataTable
Dim CurrentSQLParams As New List(Of SQLParam)
SQLMuvelet.AddInSQLParam(CurrentSQLParams, “@UserName”, SqlDbType.VarChar, ParentPageFront.UserName)
SQLMuvelet.AddInSQLParam(CurrentSQLParams, “@ProjectID”, SqlDbType.Int, ProjectID)
Try
SQLMuvelet.ExecStoredProc(CurrentSQLParams, “pView_Project_Flairs”, SqlKapcsolat1, ReturnValues1)
Catch ex As Exception
MsgBox(“Szerver oldali hiba!” & vbNewLine & “Csatlakozva vagy a hálózathoz?”, vbCritical, “Hiba!”)
ParentPageFront.ErrorHandler.WriteLog(ex)
Exit Sub
End Try
For Each r As DataRow In ReturnValues1.Rows
Dim f As New FlairCard With {.FlairIsProject = True, .FlairColor = Color.FromArgb(r.Item(“FlairColor”).ToString), .FlairName = r.Item(“FlairName”).ToString, .Clickable = False, .ParentPageFront = ParentPageFront}
ParentPageFront.ProjectPanel.CheckFlair(f)
Flairs.Add(f)
Next
FlowLayoutPanelFlairs.Controls.AddRange(Flairs.ToArray)
FlowLayoutPanelFlairs.ShowLoader = False
End Sub
It is extremly slow even at 10 or so elements. I know I am doing something wrong. Can you provide me an example for this? Sometimes SQLMuvelet.ExecStoredProc() can take long, depending on the server load it calls an MSSQL storedprocedure. I want to show a loader while it is not returning, but be able to use the controls already added and loaded to the panel.
Hi Please, could you attach a runnable sample of you issue?
If you are using a Sqlserver database, please also attach the minimal script for your sample
If we copy/paste your posted code not we equal at your environment and there are posibilty that we can reproduce you issue.
thanks and regards
I did a complete redesing on my code, to do the list filling and the control adding in seperate, and only load to screen what is currently shown. Now it is working, however the context menu click event is still not firing.
Also it seems like ContextMenuItem Click event won’t fire if you use it on a UserControl :/
Please login first to submit.