Visual studio 2010 Express (Beginner) , I am using VB
Currently attempting Datagridview, I have 3 columns in my DGV – The 2nd column consists of a combobox cbo1 and 3rd column is a Textbox txt2. Column1 is the name of the person txt1
Country & Capital are the two columns in my ‘mysql database’
I have added my database to a dataset named ds using the adapter,
adp.Fill(ds)
Country_cbo.DataSource = ds
cbo1.DisplayMember = ds.Columns("Country").ToString
Using the above code I have managed to populate the cbo1 with Countries name (using mysql database)
Trying to Achieve:
Upon selecting a value from country name function should fill the textbox with the capital of the respective country by looking into the Data set ( Which is my Database )
A guideline to acheive this would be highly appreciated.
Assuming your dataset has only one table, So
ds.Tables[0]will give you the table in dataset.Now the value is retrieved from the combo box as
combobox.SelectedItem.Then you can use a for loop to traverse through all rows of the ds.Tables[0] .
Compare the value of combo box with the column value in each row. If there is a match, retrieve the capital column’s value of that row
Example for loop (C# syntax):