How to databind a CheckedListBox control
-
First let me thank you guys, for sharing your knowledge and for responding. I am a newbie learning .NET, so plz bear with me. my question is, how to bind a CheckedListBox control in a WinForm. I did the binding, but it is not showing any values, it's not giving any error either, I wanted the CheckedListBox control to be populated at the FormLoad Event. my code is given below. I tried different ways, but still its not working. lstFacilityType is a CheckedListBox control. First, I tried this. ------------------------------------------------------------------------- lstFacilityType.DataBindings.Add(new Binding("Text",ds,"FacilityType")); ------------------------------------------------------------------------- Second, I tried the code given below, it is returning the table in the dataset. ------------------------------------------------------------------------ lstFacilityType.DataBindings.Add(new Binding("Text",ds.Tables[0],"FacilityType")); ------------------------------------------------------------------------ Thanks, for ur help. abhi
-
First let me thank you guys, for sharing your knowledge and for responding. I am a newbie learning .NET, so plz bear with me. my question is, how to bind a CheckedListBox control in a WinForm. I did the binding, but it is not showing any values, it's not giving any error either, I wanted the CheckedListBox control to be populated at the FormLoad Event. my code is given below. I tried different ways, but still its not working. lstFacilityType is a CheckedListBox control. First, I tried this. ------------------------------------------------------------------------- lstFacilityType.DataBindings.Add(new Binding("Text",ds,"FacilityType")); ------------------------------------------------------------------------- Second, I tried the code given below, it is returning the table in the dataset. ------------------------------------------------------------------------ lstFacilityType.DataBindings.Add(new Binding("Text",ds.Tables[0],"FacilityType")); ------------------------------------------------------------------------ Thanks, for ur help. abhi
If you're trying to bind the actual list, you need to need to fill the
Items
property manually. Binding theText
only binds theText
property. You should read about theDataBindings
property and theBindingManagerBase
class in the .NET Framework SDK. The code you're doing above needs to bind to theText
property of the control for which theBinding
is added (i.e.,lstFacilityType
). The rest of your expressions won't work, however, because theBinding
only works forPropertyManager
, not to bind to anIListSource
orIList
, of whichDataSet
andDataTable
are (respectively). When you bind to a data-bound control like aDataGrid
, it nows how to use theDataSource
and, optionally, theDataMember
to enumerate the collection and bind a UI element to that row. Binding how you're doing it is not the same. The results you're getting are to be expected since you're binding against an object, not its value. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles]