473,503 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Aysnc Update of Datagrid = Empty?

Hello,

I am trying to update a datagrid via an async call, but the datagrid
shows up empty. I've checked the datatable - there are indeed rows in
it...
Here is my code:
Private Sub LoadGroup()

_del = New TCP.ChangeGroupDelegate(AddressOf _oTCP.ChangeGroup)

'invoke the method asynchronously so we don't have to wait
_IA = _del.BeginInvoke(_Group, _frmGroupList, New AsyncCallback
(AddressOf BindDataGrid), _IA)

End Sub

Private Sub BindDataGrid(ByVal ar As IAsyncResult)
If ar.IsCompleted Then
'this is our callback to let us know the method is finished
'here we could use the connection
_dt = _del.EndInvoke(_frmGroupList, _IA)
'_frmGroupList.dgArticles.Invoke
(_frmGroupList.dgArticles.DataSource, New Object() {0, _dt})

_frmGroupList.dgArticles.DataSource = _dt
End If

End Sub
The program stops executing at this line but does not crash:
_frmGroupList.dgArticles.DataSource = _dt

DataGrid is empty...

Any help would be appreciated. Thanks!

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #1
2 1941
On 2004-04-19, Lucas Tam <RE********@rogers.com> wrote:
Hello,

I am trying to update a datagrid via an async call, but the datagrid
shows up empty. I've checked the datatable - there are indeed rows in
it...
Here is my code:
Private Sub LoadGroup()

_del = New TCP.ChangeGroupDelegate(AddressOf _oTCP.ChangeGroup)

'invoke the method asynchronously so we don't have to wait
_IA = _del.BeginInvoke(_Group, _frmGroupList, New AsyncCallback
(AddressOf BindDataGrid), _IA)

End Sub

Private Sub BindDataGrid(ByVal ar As IAsyncResult)
If ar.IsCompleted Then
'this is our callback to let us know the method is finished
'here we could use the connection
_dt = _del.EndInvoke(_frmGroupList, _IA)
'_frmGroupList.dgArticles.Invoke
(_frmGroupList.dgArticles.DataSource, New Object() {0, _dt})

_frmGroupList.dgArticles.DataSource = _dt
End If

End Sub
The program stops executing at this line but does not crash:
_frmGroupList.dgArticles.DataSource = _dt

DataGrid is empty...

Any help would be appreciated. Thanks!


You can't access form control properties on a background thread... You
need to do something like:

If ar.IsCompleted Then
_dt = _del.EndInvoke(....)

If _frmGroupList.InvokeRequired Then
Dim mi As New MethodInvoker(AddressOf Me.AssignDataSet)
_frmGroupList.Invoke(mi, Nothing)
Else
Me.AssignDataSet()
End If
End If

private sub AssignDataSet()
_frmGroupList.dgArticles.DataSource = _dt
End Sub

The callback will execute on a thread pool thread, so you must marshal
all calls to the form and it's controls back to the GUI thread. Heres,
an msdn article on the subject - the code is in C#, but the points are
relavent to VB.NET as well...

http://msdn.microsoft.com/library/de...ms06112002.asp

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
"Zaphod grinned two manic grins, sauntered over to the bar
and bought most of it."

- Zaphod in paradise.
Nov 20 '05 #2
Tom Shelton <to*@mtogden.com> wrote in news:OghcgJpJEHA.3380
@TK2MSFTNGP09.phx.gbl:
The callback will execute on a thread pool thread, so you must marshal
all calls to the form and it's controls back to the GUI thread. Heres,
an msdn article on the subject - the code is in C#, but the points are
relavent to VB.NET as well...


Thanks alot... that worked great : )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
14926
by: arvee | last post by:
Hi - I'm updating an Oracle table with an empty string and getting the error: An unhandled exception of type 'System.Exception' occurred in system.data.dll Additional information: Parameter...
0
305
by: vjmehra | last post by:
I have a datalist within a datagrid and I am having trouble trying to get the update command working. I am only using the one for the datagrid, but this should also update the datalist, however...
0
3531
by: Mauro | last post by:
Hi, I need a big help to resolve this problem. I need to put a usercontrol in a datagrid: this control check if the code inserted is present in a archive and if not return a error message. (In...
7
4665
by: Matthew Wieder | last post by:
Hi - I have a datagrid that has a black header and the rows alternate white and gray. The problem is that until items are added to the grid, the grid appears as a large black rectangle, which is...
4
3469
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
2
2661
by: carballosa | last post by:
Hi guys, I need to use a one row datagrid in my asp.net 1.1 application. The data source will contain 1 or 0 entries. When no rows of data are present I want to show an empty row in the datagrid...
1
2352
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
4
2261
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
13
2451
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.