我已将Fname和ID绑定到checkedListBox。我在checkedListBox中只看到了Frame。我想在checkedListBox(某些Frame)中选择一些项目。
当我按下按钮时 - 我想看到我选择的列表(我选择的ID列表)。
我正在填写checkListBox,如下所示:
SQL = "select distinct TrapName,substr(TrapNum,1,4) from TrapTbl order by substr(TrapNum,1,4) ";
adp = new OracleDataAdapter(SQL, Conn);
dsView = new DataSet();
adp.Fill(dsView, "TrapTbl");
adp.Dispose();
this.ListAtar.DataSource = dsView.Tables[0];
this.ListAtar.DisplayMember = dsView.Tables[0].Columns[0].ColumnName;
this.ListAtar.ValueMember = dsView.Tables[0].Columns[1].ColumnName;
我的问题是,当我从checkedListBox中选择一些项目并按下按钮时 - 如何获取ID列表 - ValueMember ??
答案 0 :(得分:1)
您有SelectedItem和SelectedItems作为checkedListBox的属性。
来自MSDN的示例:
private void youbutton_Clicked(object sender, System.EventArgs e)
{
// Get the currently selected item in the ListBox.
string curItem = listBox1.SelectedItem.ToString();
// Find the string in ListBox2.
int index = listBox2.FindString(curItem);
// If the item was not found in ListBox 2 display a message box,
// otherwise select it in ListBox2.
if(index == -1)
MessageBox.Show("Item is not available in ListBox2");
else
listBox2.SetSelected(index,true);
}
略有修改。