Webservice and datagrid

  • Thread starter Thread starter Mark Irvine
  • Start date Start date
M

Mark Irvine

Hi,

I am using a webservice to return a dataset holding three tables to a client
app running on Pocket PC2003. I'm using an asynchronous webservice so that
I can do other things while waiting for the data. When the call completes,
I try to bind the datset to the datagrid, however this locks the app - no
error messages it just locks up. The code is as below:

private void frmMain_Load(object sender, System.EventArgs e)
{
this.Text += " : " + this.GetEngineerName().ToLower();
wsHeatSchedule.Schedule wsSchedule = new
Heat.Mobile.wsHeatSchedule.Schedule();
AsyncCallback acSchedule = new AsyncCallback(ScheduleCallback);
wsSchedule.BeginGetSchedule(7, "23/12/2003", acSchedule, wsSchedule);
this.cboScheduledItems.DataSource = new ScheduledItem[] {new
ScheduledItem("First", "1")};
ListViewItem lviOne = new ListViewItem("First");
lviOne.SubItems.Add("One");
this.lvTest.Columns.Add("Title", -2, HorizontalAlignment.Left);
this.lvTest.Items.Add(lviOne);
this.GetFocus();
}
private void ScheduleCallback(IAsyncResult iarSchedule)
{
MessageBox.Show("Here1");
wsHeatSchedule.Schedule wsScheduleCallbck =
(wsHeatSchedule.Schedule)iarSchedule.AsyncState;
MessageBox.Show("Here2");
ds = wsScheduleCallbck.EndGetSchedule(iarSchedule);
MessageBox.Show("Here3");
dgResponseJobs.Visible = false;
MessageBox.Show(dgResponseJobs.DataSource.ToString());
}
Can anyone suggest how I can bind the data to the datagrid?

Mark
 
Alex,

Many thanks for the reply - I read the article and all is now working as
expected :)

Mark

Alex Yakhnin said:
You must use Control.Invoke since the asynchronous stuff is happening on the
different from UI thread.
Take a look at this article:

http://msdn.microsoft.com/mobility/default.aspx?pull=/library/en-us/dnppcgen
/html/use_thread_async_web_services.asp

--
Alex Yakhnin, .NET CF MVP

Mark Irvine said:
Hi,

I am using a webservice to return a dataset holding three tables to a client
app running on Pocket PC2003. I'm using an asynchronous webservice so that
I can do other things while waiting for the data. When the call completes,
I try to bind the datset to the datagrid, however this locks the app - no
error messages it just locks up. The code is as below:

private void frmMain_Load(object sender, System.EventArgs e)
{
this.Text += " : " + this.GetEngineerName().ToLower();
wsHeatSchedule.Schedule wsSchedule = new
Heat.Mobile.wsHeatSchedule.Schedule();
AsyncCallback acSchedule = new AsyncCallback(ScheduleCallback);
wsSchedule.BeginGetSchedule(7, "23/12/2003", acSchedule, wsSchedule);
this.cboScheduledItems.DataSource = new ScheduledItem[] {new
ScheduledItem("First", "1")};
ListViewItem lviOne = new ListViewItem("First");
lviOne.SubItems.Add("One");
this.lvTest.Columns.Add("Title", -2, HorizontalAlignment.Left);
this.lvTest.Items.Add(lviOne);
this.GetFocus();
}
private void ScheduleCallback(IAsyncResult iarSchedule)
{
MessageBox.Show("Here1");
wsHeatSchedule.Schedule wsScheduleCallbck =
(wsHeatSchedule.Schedule)iarSchedule.AsyncState;
MessageBox.Show("Here2");
ds = wsScheduleCallbck.EndGetSchedule(iarSchedule);
MessageBox.Show("Here3");
dgResponseJobs.Visible = false;
MessageBox.Show(dgResponseJobs.DataSource.ToString());
}
Can anyone suggest how I can bind the data to the datagrid?

Mark
 
Back
Top