在列表框/复选框中添加数据集值 [英] Add Dataset value in listbox / checklistbox
问题描述
我正在尝试在comboBox3_SelectedIndexChanged事件的列表框或复选框中添加值.
为此,我使用了查询.......
查询正确,因为我想从数据库中选择带有已删除MainTest的所有字段
但是选择此选项后,我无法在列表框或复选框中添加这些选定的项目.
我知道,
假设在查询中我特别使用了列名,则将其添加到列表框/复选框中
但我不想执行该任务,我希望从给定查询中选择所有选定的值/项目.
请提供有关此主题的一些帮助!!!
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!!!
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
推荐答案
CheckedListBox具有DataBindings属性.
尝试使用它.
CheckedListBox has a DataBindings property.
Try using that.
commObj = New OleDbCommand("SELECT ALL * FROM MainTest WHERE MainT = '" & h & "'", cnn)
myDataSet1.Clear()
myAdapter = New OleDbDataAdapter(commObj)
myAdapter.Fill(myDataSet1, "cDetails")
CheckedListBox1.DataSource = myDataSet1
使用此链接作为参考 http://msdn.microsoft.com/en -us/library/system.windows.forms.control.databindings.aspx [
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.
尝试这个.
try this one.
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()
Regards,
@iamsupergrasya
这篇关于在列表框/复选框中添加数据集值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!