Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
hi all,

i'm inserting values into datagridview by using thread. A thread was inserted a value, it works well. But datagridview scroll is not working.

VB
sub download_1( )

                                    Dim fpcount As String = ""
                                    fpcount = fingertmp(bEnrollNumber.ToString).ToString.Trim
                                    If fpcount <> 0 Then
                                        DV2.Rows.Insert(0, 1)
                                        DV2.Rows(0).Cells(1).Value = bEnrollNumber
                                        If bName.Length = 0 Then
                                            DV2.Rows(0).Cells(2).Value = bEnrollNumber
                                        Else
                                            DV2.Rows(0).Cells(2).Value = bName
                                        End If

                                        DV2.Rows(0).Cells(3).Value = bPassword
                                        If bPrivilege = 0 Then
                                            ad1 = "User"
                                        Else
                                            ad1 = "Admin"
                                        End If
                                        DV2.Rows(0).Cells(4).Value = ad1
                                        DV2.Rows(0).Cells(5).Value = ef
                                        DV2.Rows(0).Cells(6).Value = fpcount
                                        DV2.Rows(0).Cells(7).Value = "0"
                                        DV2.Rows(0).Cells(8).Value = "0"
                                        ctemp = Convert.ToInt32(fpcount) + ctemp
                                        Me.ProgressBar1.Value = (ctemp / finger) * 100
                                        Me.ProgressBar1.Update()
                                        Me.lblprg.Text = ProgressBar1.Value & "%"
                                        lblprg.Refresh()
                                    End If
   End sub



code sample moved from comment - Maciej Los
Posted
Updated 14-Mar-14 9:36am
v2
Comments
Sergey Alexandrovich Kryukov 13-Mar-14 8:55am    
Without some code sample, there is nothing I can tell. Did you use Control.Invoke or Control.BeginInvoke?
—SA
Maciej Los 13-Mar-14 16:41pm    
What a question?
vivekrd18 14-Mar-14 1:58am    
--content has been moved to the question--
vivekrd18 14-Mar-14 1:57am    
--comment has been deleted--

1 solution

You absolutely CAN NOT TOUCH a UI control from a background thread. You will end up with very weird problems that are very difficult to reproduce and track down.

If you want to add data to a control from a background thread you have to Invoke a method that is specifically written to do this from your background thread code.

Read this[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900