Groups | Blog | Home
all groups > dotnet windows forms databinding > december 2007 >

dotnet windows forms databinding : Combobox DropDown Binding


SteveKing
12/13/2007 4:08:01 PM
I'm having difficulty binding a combobox which is of the dropdownstyle of
dropdown. According to documentation you can either select a value from the
dropdown list or type a value into the textbox part of the control. If I
bind to the SelectedValue as in '.DataBindings.Add("Text", bsComp, "Cage")' I
have absolutely no problem, but my requirement is that the user be able to
save a non-listed value to the database. Since the string value in the .Text
property is what I wanted to save, I tried to bind like a textbox but that
doesn't work either. Any help would be appreciated.

With Me.cboCageComp
.DataSource = cageTable
.DisplayMember = "Cage"
.ValueMember = "Cage"
.DataBindings.Add("Text", bsComp, "Cage")
SteveKing
12/14/2007 4:46:01 PM
The solution was simple. Stop trying to use DataSets to bind comboboxes and
simply use a datareader to cbo.Items.Add a class to the combobox. Then bind
to the Text property using DataBinding.Add("Text", bsItem, "FieldName"). It
works great and is faster.


[quoted text, click to view]
Martin M
2/20/2008 9:26:24 AM
Could try DaisyCombo from www.springsys.com


-martin


[quoted text, click to view]

RB
5/16/2008 4:21:23 PM
' Create a ComboClass.vb

'================

Public Class CmbIdStr

Public txtShow As String

Public idValue As Integer

Public TextName As String

Sub New(ByVal pText As String, ByVal pidValue As Integer, ByVal pTestName As
String)

Me.txtShow = pText

Me.idValue = pidValue

Me.TextName = pTestName

End Sub

Overrides Function ToString() As String

Return txtShow

End Function

End Class

'=============

Private Sub AddMyEntry()

Dim cmbBox As ComboBox = MyCombo

OrdersBindingSource.RaiseListChangedEvents = False

cmbBox.Items.Add(New CmbIdStr("My Text", MyId.ToString,
MySecondID.ToString))

OrdersBindingSource.RaiseListChangedEvents = True



End Sub
--
remove underscore to send me mail, no spam

[quoted text, click to view]

AddThis Social Bookmark Button