Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / January 2006

Tip: Looking for answers? Try searching our database.

Datagrid DataSource and DataMember properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Faris - 23 Jan 2006 10:27 GMT
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.
Bart Mermuys - 23 Jan 2006 11:10 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.