Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to add value in listbox or checklistbox on comboBox3_SelectedIndexChanged event.

for this i used query.......
query correct because i want select all field with releted MainTest from database
but after selecting this i cant possible to add these selected item in listbox or checklistbox.
i know,
suppose in query i used particularly column name then that will be add in listbox/checklistbox
but i dont want do that task, i want all selected value/item from given query.

please provide some help on this topic!!!

VB
commObj = New OleDbCommand("SELECT ALL * FROM MainTest WHERE MainT = '" & h & "'", cnn)
       myDataSet1.Clear()
       myAdapter = New OleDbDataAdapter(commObj)
       myAdapter.Fill(myDataSet1, "cDetails")
        Dim ds As DataRow
        ds = myDataSet1.Tables("cDetails").Rows
       For Each ds As DataRow In myDataSet1.Tables("cDetails").Rows

           CheckedListBox1.Items.Add(ds(" what i do here      ").ToString())

       Next
Posted
Updated 7-Feb-12 21:24pm
v4
Comments
Herman<T>.Instance 8-Feb-12 3:27am    
in "what i do here" you have to state the columnname.
What sql server are you using? If MS SQL server you can omit the ALL keyword. with select * you get all.

CheckedListBox has a DataBindings property.

Try using that.

VB
commObj = New OleDbCommand("SELECT ALL * FROM MainTest WHERE MainT = '" & h & "'", cnn)
       myDataSet1.Clear()
       myAdapter = New OleDbDataAdapter(commObj)
       myAdapter.Fill(myDataSet1, "cDetails")
       CheckedListBox1.DataSource = myDataSet1



Use this link for referencehttp://msdn.microsoft.com/en-us/library/system.windows.forms.control.databindings.aspx[^]

*Mark as answer if this solved your query.
 
Share this answer
 
v2
Comments
harishtaware 8-Feb-12 4:02am    
i cant get databinding part when i saw checkedlist box property that time
in databinding also having 4 different section what part are changed there.

and when i modify my code according to your changed then

error shows
Cannot bind to the property 'Value' on the target control. Parameter name: PropertyName
[no name] 8-Feb-12 4:09am    
Hi,
I've updated, there is a datasource property. Just that it doesn't show up in Intellisense. Try it and tell me
harishtaware 8-Feb-12 4:16am    
i cant find datasource property.
i jst see databinding in that selectindex,value,item and tag

no any datasource property available there
i am using vs2008
[no name] 8-Feb-12 4:32am    
It doesn't appear in intellisense. Just code and build.
harishtaware 8-Feb-12 5:06am    
Jyothikarthik_N its working but till the dataset item are not added in checklist box...:(

in list content shows system.data.DataViewManagerListItemType
try this one.

VB
commObj = New OleDbCommand("SELECT ALL * FROM MainTest WHERE MainT = '" & h & "'", cnn)
Dim dt as dataTable
       myDataSet1.Clear()
       myAdapter = New OleDbDataAdapter(commObj)
       myAdapter.Fill(myDataSet1, "cDetails")
 dt = myDataSet1.Tables(0)

 'checklistbox
        chkData.DataSource = dt
        chkData.DataTextField = "textfield" 'text you want to appear
        chkData.DataValueField = "idvaluefield"  'value of the field
        chkData.DataBind()


VB
Regards,
@iamsupergrasya
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900