vb .net中的Datagridview和线程 [英] Datagridview and thread in vb .net

查看:104
本文介绍了vb .net中的Datagridview和线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用线程将值插入datagridview。一个线程插入了一个值,它运行良好。但是datagridview滚动不起作用。



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.

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







代码示例从评论中移除 - Maciej Los

推荐答案

你绝对无法从后台线程中获取UI控件。你最终会遇到非常奇怪的问题,很难再现和追踪。



如果你想从后台线程向控件添加数据你必须从后台线程代码调用专门编写的方法。



阅读这个 [ ^ ]。
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[^].


这篇关于vb .net中的Datagridview和线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆