Bound Combobox Updating

S

Sreppohcdoow

I have a combobox bound to a dataset at design time.

If I add rows to the bound table in code before displaying my control, the
rows show up in the combobox as expected.

However, I want to be able to add items to the combobox at run time... I've
tried the _Leave event to update... i.e., taking the value in the combobox
and adding it to the table, but this doesn't cause the combobox to refresh
it's list...

So I tried adding a textbox and an add button... i.e., taking the value in
the textbox, adding it to the dataset (which I know is working)... but
again, can't figure out how to get the combobox to 'refresh' it's list of
values.

Ideally, I'd like to just use the combobox to add values, but if need be, I
can go the textbox route.

Thx for any help,
MS
 
O

Otis Mukinfus

I have a combobox bound to a dataset at design time.

If I add rows to the bound table in code before displaying my control, the
rows show up in the combobox as expected.

However, I want to be able to add items to the combobox at run time... I've
tried the _Leave event to update... i.e., taking the value in the combobox
and adding it to the table, but this doesn't cause the combobox to refresh
it's list...

So I tried adding a textbox and an add button... i.e., taking the value in
the textbox, adding it to the dataset (which I know is working)... but
again, can't figure out how to get the combobox to 'refresh' it's list of
values.

Ideally, I'd like to just use the combobox to add values, but if need be, I
can go the textbox route.

Thx for any help,
MS
I am guessing here, so can't guarantee this will work, but this is what you have
to do when refreshing a Grid in VS 2005 .Net 2.0:

set the ComboBox DataSource to null and then set it to the DataSet again. That
will reload the CommboBox from the dataset. It sounds like a kludge, but with
grids it works.

There may be a better way to do both. If someone knows one I'd like to know
about it.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
V

Vayse

Otis Mukinfus said:
There may be a better way to do both. If someone knows one I'd like to
know
about it.

So would I! I've found that data bound combo boxes is VB2005 cause a lot of
problems. As mentioned, sometimes the combo does not populate correctly.
Other times, you can pick valid data, but the focus just locks on the box.
I've had no problems with unbound combo boxes.
Vayse
 
O

Otis Mukinfus

So would I! I've found that data bound combo boxes is VB2005 cause a lot of
problems. As mentioned, sometimes the combo does not populate correctly.
Other times, you can pick valid data, but the focus just locks on the box.
I've had no problems with unbound combo boxes.
Vayse
Vayse,

Since Combo boxes are typically (but not always) used to display a fixed list of
values for users to choose from, I rarely bind them. I just populate them with
a display class that contains a string to contain the description and an integer
to point to the database row in a lookup table. The class's ToString() method
is overloaded to return the description string, which is what the combo box will
display in the list. From there I get whatever they chose using information from
the display or ID properties of the class.

Good luck with your project.


Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
V

Vayse

Since Combo boxes are
typically (but not always) used to display a fixed list of
values for users to choose from, I rarely bind them. I just populate them
with
a display class that contains a string to contain the description and an
integer
to point to the database row in a lookup table. The class's ToString()
method
is overloaded to return the description string, which is what the combo
box will
display in the list. From there I get whatever they chose using
information from

Indeed, I usually do the same thing myself. Below is the code I use.
The problem with the combo boxes is another reason to use unbound forms.
Regards
Vayse



'*******************************************************************
Do While dbDataReader.Read
iloop += 1
Me.comAssetCode.Items.Add(New CodeBoxItem(iLoop,
dbDataReader("Desc").ToString, dbDataReader("AssetCode").ToString))
Loop
Me.comAssetCode.EndUpdate()


Public Class CodeBoxItem

' For combo box, where we use a Code and description

Private listItemData As Object
Private listItemText As String
Private listItemCode As String

Public Overrides Function ToString() As String
Return listItemText
End Function

Public Sub New(ByVal ItemData As Object, ByVal itemText As String, ByVal
itemCode As String)
listItemData = ItemData
listItemText = itemText
listItemCode = itemCode
End Sub

Public ReadOnly Property Data() As String
Get
Data = listItemData
End Get
End Property

Public ReadOnly Property Text() As String
Get
Text = listItemText
End Get

End Property

Public ReadOnly Property Code() As String
Get
Code = listItemCode
End Get

End Property

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top