Author Topic: Combobox datasource update  (Read 2582 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Combobox datasource update
« on: March 22, 2009, 01:36:28 PM »
First, let me thank everyone for the help I have gotten recently. I am doing alot more programming stuff and I am delving into areas where I previously didn't have to go .. but it is a living.

Background:
I have a textbox that is bound to a datasource
Code: [Select]
tbArtist.DataBindings.Add(New Binding("text", bindClients, "Artist"))
However, since there may be any number of items that can be placed in this textbox, I would like to make it a combo box and keep the data entered as data to use for filling the combobox with the default values to select from.


What I have tried:
Code: [Select]
cbArtist.DataBindings.Add(New Binding("text", bindClients, "Artist"))
Try
    Dim ds As DataSet = GetMyData("Artists", "ID")
    With cbArtist
        .DataSource = ds.Tables("Artists")
        .DisplayMember = "Atrist"
        .SelectedIndex = 0
    End With
Catch ex As Exception
    MsgBox("Cannot load Artist list", MsgBoxStyle.Information)
End Try

So I have tried the above, and I can set the datasource for the combobox data, and the text value remains bound to the dataset, but now, if the user enters something not in the combobox, I'd like to add it back to the "Artists" table (i.e. the DataSource for the combobox) so the next time the user selects the combobox, it will be in the list.

Is there a way to do this automatically or do I have to code the whole thing by creating a dataset and updating it manually.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Draftek

  • Guest
Re: Combobox datasource update
« Reply #1 on: March 23, 2009, 10:24:10 AM »
You already have a dataset, just update it and then you may have to refresh your bindings for the combo box.

Although, you may want to do some validation and then go ahead and update the database itself and then refresh your bindings.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Combobox datasource update
« Reply #2 on: March 23, 2009, 10:41:37 AM »
I figured this out this weekend ... DUH ... I loaded a dataset into the combo box, why not simply update it when the user changes the textbox .. of course I had some trial and error .. especially if the dataset was empty or if a new record was added to my dataset bound to the text property.

I had to utilize some tokens, focus events and text changed events to suss it all out, but it is working well now.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie