2010-02-26 29 views
1

我已将Fname和ID绑定到我的checkedListBox。我在checkedListBox中只看到了Frame。我想挑选checkedListBox中的一些项目(某些框架)。checkedListBox和SQL查询

当我按下按钮 - 我想看到我选择的列表(我选择的ID列表)。

我被灌checkedListBox这样的:

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?

回答

1

您有SelectedItemSelectedItems作为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); 
} 

稍加修改。