Gold
Gold

Reputation: 62424

checkedListBox and SQL queries

I have bind Fname and ID to my checkedListBox. I see in the checkedListBox only the Frame. I want to pick some items in the checkedListBox (some Frame).

When I press the button - I want to see the list that I picked (the list of ID that I pick).

I was filling checkedListBox like this:

 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;

My question is, when I pick some items from the checkedListBox and press a button - how do I get a list of the ID - the ValueMember??

Upvotes: 1

Views: 531

Answers (1)

Filip Ekberg
Filip Ekberg

Reputation: 36287

You have SelectedItem and SelectedItems as properties of the checkedListBox.

An Example from 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);
}

Slightly modified.

Upvotes: 1

Related Questions