.NET 2.0 binding method no longer works
Hi guys
In .NET 2.0, I used to bind a combobox like this:
Code Snippet
DataSetClass newDataset = new DataSetClass();
cboGroup.DataSource =
newDataSet;cboGroup.ValueMember =
"tblGroups.GroupID"
;cboGroup.DisplayMember =
"tblGroups.GroupName"
;
But in .NET 3.0, with a WPF Combobox, theDataSource,ValueMemberandDisplayMemberproperties no longer exist. I'm wondering how I can replicate the above behaviour with the new properties (reading of samples has not cleared up how I can do this in code thus far.)
I know you can databind in Blend, but only to adataset class, not adataset instanceof a dataset class where the instance (newDataset) is generated in code.
Thanks for your help,
Ben
[1135 byte] By [
-=B3N=-] at [2008-1-4]
These still exist, with slightly different semantics.
DataSource = ItemsSource
ValueMember = SelectedValuePath
DisplayMember = DisplayMemberPath
Thanks Doug. Is there a similar property for the passwordbox or textbox or label control?
Eg:
Code Snippet
passwordbox.? = mydataset.tblusers;
passwordbox.? = "Password";
I tried passwordbox.password but this just set it to "Password" as a string and not as a fieldname.
With textbox I used to use databindings.add
This is where you probably need to dig into the binding system.
For a TextBox this might look like:
textBox.DataContext = mydataset.tblusers; textBox.SetBinding(TextBox.TextProperty, new Binding("Password")); Label is similar, but you can't actually bind the password of a PasswordBox, presumably for security reasons.
Hi guys, anybody able to help me out here?
I have two datatables (tblServers and tblLogins) in a dataset. tblServers has a primary key of ServerName, and tblLogins has a shared primary key of ServerName and Email. There is a foreign key, FK_tblServers_tblLogins, linking the ServerName field of the two tables.
I'm trying to bind a combobox, cboEmail, to the Foreign Key ServerName field (the value) and display in the combobox the Email (the displaymember), as follows:
Code Snippet
cboEmail.ItemsSource =
ds.tblLogins //Also tried ds.tblServers, to no availcboEmail.SelectedValuePath = "FK_tblServers_tblLogins.ServerName";
cboEmail.DisplayMemberPath = "Email";
In .NET 2.0, I used to do it like this:
Code Snippet
cboEmail.DataSource =
ds;cboEmail.ValueMember =
"tblServers.FK_tblServers_tblLogins.ServerName"
;cboEmail.DisplayMember =
"tblServers.FK_tblServers_tblLogins.Email"
; But can't figure out how to do it in .NET 3.0.
Thanks in advance for your help. I really appreciate it!