I have a Typed Dataset "dsDoc" that contains one DataTable, "Documents".
This was produced using a DataAdaptor's generate dataset command. I can
databind to a datagrid either by
1) Setting the grid's Datasource to dsDoc.Documents
2) Setting the Datasource to dsDoc and the DataMember to Documents.
Both seem to work but I am wondering which is the correct way of doing it?
Leading on from that, if I want to use a currency manager which of the
following would I use
_cm = this.BindingContext[dsDoc.Documents] as CurrencyManager;
or
_cm = this.BindingContext[dsDoc, "Documents"] as CurrencyManager;
Finally if I then want to databind a Combobox to one of the same fields as
the grid which of these is correct?
cmbStatus.DataBindings.Add("SelectedValue", dsDoc, "Documents.StatusId");
TIA.
John.
Hi,
>I have a Typed Dataset "dsDoc" that contains one DataTable, "Documents".
>This was produced using a DataAdaptor's generate dataset command. I can
[quoted text clipped - 4 lines]
>
> Both seem to work but I am wondering which is the correct way of doing it?
It doesn't matter that much what you choose, but you'll need to be
consistent:
- if you want other Control's to navigate dependent
- if you want to get the CurrencyManagaer.
> Leading on from that, if I want to use a currency manager which of the
> following would I use
[quoted text clipped - 4 lines]
>
> _cm = this.BindingContext[dsDoc, "Documents"] as CurrencyManager;
The one you use _depends_ on how you bound.
> Finally if I then want to databind a Combobox to one of the same fields as
> the grid which of these is correct?
>
> cmbStatus.DataBindings.Add("SelectedValue", dsDoc, "Documents.StatusId");
Same here, depends on how you bound the DataGrid, if the DataGrid's
DataSource is a DataSet, then you would use:
cmbStatus.DataBindings.Add("SelectedValue", dsDoc, "Documents.StatusId");
If the DataGrid's DataSource is a DataTable, then you'll need to use:
cmbStatus.DataBindings.Add("SelectedValue", dsDoc.Documents, "StatusId");
One thing though, when you use the designer to simple bind a Control (eg.
ComboBox.SelectedValue, Textbox.Text, etc) to a typed DataSet, then it will
always use the DataSet as the DataSource, never the DataTable.
HTH,
Greetings
> TIA.
>
> John.
John Faris - 23 Jan 2006 11:35 GMT
Hi Bart.
Thanks for the help.
> One thing though, when you use the designer to simple bind a Control (eg.
> ComboBox.SelectedValue, Textbox.Text, etc) to a typed DataSet, then it
> will always use the DataSet as the DataSource, never the DataTable.
Not sure I understand this last bit. If I use the designer and set a
combobox's SelectedValue databinding to dsDoc - Documents.StatusId, which is
the equivalent of DataSet - DataTable.Field, are you are saying it will
ignore the DataTable part?
Thanks.
Bart Mermuys - 23 Jan 2006 12:06 GMT
Hi,
> Hi Bart.
>
[quoted text clipped - 8 lines]
> is the equivalent of DataSet - DataTable.Field, are you are saying it will
> ignore the DataTable part?
No, not ignored, i just meant that if you bind a ComboBox to a _typed_
DataSet using the designer, that it will always result in:
cmbStatus.DataBindings.Add("SelectedValue", dsDoc, "Documents.StatusId");
Never in this:
cmbStatus.DataBindings.Add("SelectedValue", dsDoc.Documents, "StatusId");
HTH,
Greetings
> Thanks.