Combobox and databinding

EllenHeijmans

New member
Joined
Dec 23, 2009
Messages
1
Programming Experience
5-10
I have a problem with a combobox and no page on the Internet has been able to help me so far. So I hope that one of you can.

I have a form (with information about clients) with textboxes binded to a dataview. One of the columns in the dataview contains a number that tells me what kind of client it is. I don't my users want that my users have to fill in a number in a textbox, but I want them to choose a item from a combobox. De selected value should be the value that is actually saved in the database.

This is my code:

Dim cmd As New SqlCommand
Dim dr As SqlDataReader

VerbindingMaken()

cmd.Connection = cnnVraagbaak
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "relatie.proc_OpvragenRelatiesoort"
daRelatie.SelectCommand = cmd
daRelatie.Fill(dsRelatie, "Relatiesoort")

cbo.DataSource = dsRelatie.Tables("Relatiesoort")
cbo.ValueMember = dsRelatie.Tables("Relatiesoort").Columns(0).ToString
cbo.DisplayMember = dsRelatie.Tables("Relatiesoort").Columns(1).ToString
cbo.DataBindings.Add("SelectedValue", dsRelatie.Tables("Relaties"), "Relatiesoort")




De Datasource is the information in my combobox. With Databindings I'm trying to bind it to my dataset (or view, that doesn't work either) with clients. Every time I get a NullReferenceExeption. The moment I remove the line cbo.DataSource = dsRelatie.Tables("Relatiesoort"), I don't get an error, but it doesn't work either.

That dataset is filled (I've checked) and also the derived view. The column Relatiesoort exists.

What do I have to do to make it possible for my users to choose an item from a combobox and save the selected value to the underlying dataset?
 
Are you working in an environment that supplies some sort of form designer? (It seems that a form of some sort is the only place that a combobox would be of use. . . .) If so, the properties page should have spaces for a data source (the outside table that associates your Key or code with your text string), a values field (the code or key that you want stored in the form's underlying table or query), and a display field (showing the text strings that you want your users to select among). There are corresponding properties accessible from, for example, VB 2008 code. I have not had to use them because I've used properties boxes; also, the object model and properties likely differ according to which library the combobox derives from.
 
Back
Top