Advertisement

01.13.2008 at 02:52PM PST, ID: 23079648
[x]
Attachment Details

Updating datagridview via thread.

Asked by sgaggerj in Microsoft Visual Basic.Net

Tags: VB.NET 2005

Hi all,

I'm trying to add rows to a datagridview via a thread.

I'm reading from a database, creating a row, and adding the row.

i'd like to end up with the user seeing the rows being added, which is why i used the thread - otherwise the program seems to hang when adding several hundred rows.

my problem is that the program crashes (the vshost.exe crashes sometimes too - clean install xp, clean install vs2005 - full updates) whenever i add the row

the code below is exactly what i'm using - except for loadinventorygrid, which i've trimmed down alot for simplicity.


Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
Private Delegate Sub AddRowDelegate(ByRef row As DataGridViewRow)
 
public sub new()
Me.InventoryGrid.Rows.Clear()
Me.MyThread = New Threading.Thread(New Threading.ThreadStart(AddressOf Me.LoadInventoryGrid))
Me.MyThread.Start()
end sub
 
Private Sub AddRow(ByRef row As DataGridViewRow)
        If Me.InvokeRequired Then
            Dim usd As New AddRowDelegate(AddressOf Me.AddRow)
            Me.Invoke(usd, New Object() {row})
        Else
' This is where the code crashes
            InventoryGrid.Rows.Add(row)
        End If
    End Sub
 
Public Sub LoadInventoryGrid()
'read from my database into an arraylist
' loop through the arraylist creating a row, adding cells as i go
dim my_list as new arraylist
dim r as datagridviewrow
 
for i as integer=0 to my_list / count -1
r=new datagridviewrow
dim c as new datagridviewtextboxcell
c.value=1 ' some value
r.cells.add(c)
next i
 
' add the row
addrow(r)
end sub
[+][-]01.13.2008 at 03:02PM PST, ID: 20649737

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.13.2008 at 03:12PM PST, ID: 20649762

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.13.2008 at 03:25PM PST, ID: 20649840

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.13.2008 at 03:31PM PST, ID: 20649854

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.13.2008 at 03:32PM PST, ID: 20649857

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01.13.2008 at 03:56PM PST, ID: 20649930

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.13.2008 at 03:58PM PST, ID: 20649933

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.14.2008 at 01:03AM PST, ID: 20651792

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01.14.2008 at 01:30AM PST, ID: 20651896

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: VB.NET 2005
Sign Up Now!
Solution Provided By: jpaulino
Participating Experts: 2
Solution Grade: B
 
 
[+][-]01.22.2008 at 05:27AM PST, ID: 20713930

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628