473,382 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Bind / Synchronize a comboBox to a filed the current record

Hello,

I have the controls on my form display the values of the currently
selected row of the dataGrid. There are a few fields that I have in my
data table where I have the user select a value from a comboBox. The
comboBox is populated from a lookup table in my database. The comboBox
displays the range of choices and when the user selects one the
comboBox stores the appropriate ID field in the field of my data table.
The above is easy enough, but how do I wire up the dataGrid/comboBox so
that as the user moves through the records in the dataGrid that the
comboBox will display the proper value for each row?

Thank you,
- Doug

Nov 21 '05 #1
1 1929
Dbuchan,

I have changed an older sample from me what was terrible quick and dirty.
Although this has maybe as well some errors, is it in my opinion better to
understand. The first part is only building of the tables.

'\\datagrid sample with combobox outside
'needs a datagrid, a combobox and two buttons on a form
'to start do the button create ds and cancel and a dataset will be created
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet("Test")
Dim dtName As New DataTable("Names")
Dim dcIdName As New DataColumn("IdName")
Dim dcName As New DataColumn("Name")
Dim dcCountryN As New DataColumn("Country")
dtName.Columns.Add(dcIdName)
dtName.Columns.Add(dcName)
dtName.Columns.Add(dcCountryN)
ds.Tables.Add(dtName)
dtName.LoadDataRow(New Object() {"0", "Herfried K. Wagner", "Austria"},
True)
dtName.LoadDataRow(New Object() {"1", "Cor Ligthert", "Holland"},
True)
dtName.LoadDataRow(New Object() {"2", "Armin Zingler", "Germany"},
True)
dtName.LoadDataRow(New Object() {"3", "Ken Tucker", "Florida"},
True)
dtName.LoadDataRow(New Object() {"4", "Jay B. Harlow", "New York"},
True)
dtName.LoadDataRow(New Object() {"5", "Terry Burns", "England"},
True)
Dim dtCountry As New DataTable("Countries")
dtCountry.Columns.Add("Country")
dtCountry.Columns.Add("IdCountry")
dtCountry.LoadDataRow(New Object() {"0", "Austria"}, True)
dtCountry.LoadDataRow(New Object() {"1", "Germany"}, True)
dtCountry.LoadDataRow(New Object() {"2", "Holland"}, True)
dtCountry.LoadDataRow(New Object() {"3", "Georgia"}, True)
dtCountry.LoadDataRow(New Object() {"4", "Florida"}, True)
dtCountry.LoadDataRow(New Object() {"5", "England"}, True)
ds.Tables.Add(dtCountry)
Dim dv As DataView = New DataView(ds.Tables(0))
dv.AllowNew = False
DataGrid1.DataSource = dv
ComboBox1.DataSource = ds.Tables(1).DefaultView
ComboBox1.ValueMember = "IdCountry"
ComboBox1.DisplayMember = "Country"
ComboBox1.DataBindings.Add(New Binding("SelectedValue", dv,
"Country"))
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
Me.BindingContext(DataGrid1.DataSource).EndCurrent Edit()
End Sub
End Class
///

I hope this helps a little bit?

Cor
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Zlatko Matić | last post by:
I have several forms hierarchycaly nested in each other (form/subform/subform/subform....). The final form is "continous form", while parent forms are single forms through which navigation was...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
4
by: Steve | last post by:
C# I have some combo boxes, full of lookup descriptions. When I retrieve a dataset for my record, the values that need binding to the combos are the actual record IDs that relate to these...
1
by: Patrik Zdarsa | last post by:
Hi, I'm try VS 2005 and need UPDATE database record in viewform, all working when every filed is type TextBox (html INPUT) but I need change one TextBox to Listbox or dropdownlist and read data...
1
by: Simon | last post by:
Dear reader, With a combobox I can go to a selected record picked in the pull down list. And in the same time the record navigation field shows the selected record number from the...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
5
by: Anthony Bollinger | last post by:
I have two tables in a master-detail relationship. When I make a selection in one combobox, how do I have it display the values from a second combobox? Each table has a key and a text value for...
3
by: Yas | last post by:
Hi everyone I am trying to create a DELETE Trigger. I have 2 tables. Table1 and Table2. Table 2 has all the same fields and records as Table1 + 1 extra column "date_removed" I would like that...
3
KalariaNitya
by: KalariaNitya | last post by:
Hello all, i m stuck in how to bind combobox with valuemember i have four fields in database like..in table agent_master id =a00001 firstname = nitya middlename = v lastname = kalaria
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.