Groups | Blog | Home
all groups > dotnet windows forms databinding > november 2006 >

dotnet windows forms databinding : Newbie which is very stuck - VB 2005



Oh-its-all-gone-wrong
11/15/2006 1:30:48 PM
Hi There All,

I wonder if somebody could possible help me a little with my "Very Simple"
project that i just can get to work. I`ve been searching Google for about 2
weeks now but can`t find anything that seems to help me:( My Project is a
simple Address book. I have 3 Tables, with a Data-Realtion.

Table One:

TBoneID
Name
Address
Telephone
Fax
E-Mail
Website
Current_Occupation
Current_Satus

Table Two:

TBtwoID
Current_Occupation

Table Three:

TBthreeID
Current_Status

On My Project I have one form. The Form has a datagrid on as well as Text
Box`s for Name, Address, etc, etc. It Also has 2 Combo Box`s on to lookup
Current Occupation and Currecnt Status.

Everything works fine, but when i click on a different row in my datagrid,
the changes are not reflected on my ComboBox, the ComboBoxs stay on the data
for the first row I click on and i need it to change when i click on a
different row in my data table, and to change to what the data is supposed
to be for that row i clicked on. (If you get my drift?)

Anybody able to point me in the right direction or give me some code
snippits? I think its something to do with Currecny Manager but am not 100%.
Hope all the above makes sense and somebody could kindly help me. Im Using
VB 2005

Sorry to be stupid and probably ask such a silly question.

Many Thanks

Bart Mermuys
11/15/2006 2:57:15 PM
Hi,

[quoted text, click to view]

Well, if you are using VB2005, you should have a BindingSource for each
table (on the Form or in code), each BindingSource has the DataSet as the
DataSource and a tablename as DataMember.

Then if you bind like this (code or designer) it should work:

// master
DataGridView1.DataSource = TableOneBindingSource
NameTextBox.DataBindings.Add("Text", TableOneBindingSource, "Name")
....

// lookup1
CurrentOccupationCombo.DataSource = TableTwoBindingSource
CurrentOccupationCombo.DisplayMember = "Current_Occupation"
CurrentOccupationCombo.ValueMember = "TBtwoID";
CurrentOccupationCombo.DataBindings.Add("SelectedValue",
TableOneBindingSource, "Current_Occupation");

// lookup 2
CurrentStatusCombo.DataSource = TableThreeBindingSource
CurrentStatusCombo.DisplayMember = "Current_Status"
CurrentStatusCombo.ValueMember = "TBthreeID"
CurrentStatusCombo.DataBindings.Add("SelectedValue", TableOneBindingSource,
"Current_Status");


Notice that TextBox.Text, ComboBox.SelectedValue and DataGridView.DataSource
are all using the same TableOneBindingSource, that makes them navigate
together.

HTH,
Greetings

[quoted text, click to view]

AddThis Social Bookmark Button