Tom Knowlton
asked on
i keep forgetting this - Find List Box item by ValueMember not List Box Index
If I pick an item from a ListBox that is assigned a DataSource and has the DisplayMember and ValueMember assigned for each item in the list......when I pick an item in the ListBox....I want to store that value....and then use that value to programmatically select the same item in another list box........which I know will have the same ValueMember value as the other ListBox item had.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
private void listBoxRDOnly_DoubleClick( object sender, System.EventArgs e)
{
//get ID
int tempAEID = ReturnListBoxSelectedValue (this.list BoxRDOnly) ;
//navigate to first tab
this.tabControl1.SelectedT ab = 1;
//check Active filter if it is unchecked
if(!this.checkBoxShowActiv e.Checked)
{
this.checkBoxShowActive.Ch ecked = true;
}
//refresh list box
RefreshAEPOOLList();
//programmatically pic the AE ID ////////////////////////// HOW DO I DO THIS......THIS IS A DIFFERENT LIST BOX on another TAB PAGE.....BUT HAS THE SAME DATASOURCE, etc.
// set selected value to list box
ListBox.SelectedValue = tempAEID;
}
private int ReturnListBoxSelectedValue (ListBox lb)
{
if (lb.SelectedValue != null)
{return int.Parse(lb.SelectedValue .ToString( ));}
else { return 0;}
}
{
//get ID
int tempAEID = ReturnListBoxSelectedValue
//navigate to first tab
this.tabControl1.SelectedT
//check Active filter if it is unchecked
if(!this.checkBoxShowActiv
{
this.checkBoxShowActive.Ch
}
//refresh list box
RefreshAEPOOLList();
//programmatically pic the AE ID //////////////////////////
// set selected value to list box
ListBox.SelectedValue = tempAEID;
}
private int ReturnListBoxSelectedValue
{
if (lb.SelectedValue != null)
{return int.Parse(lb.SelectedValue
else { return 0;}
}
ASKER
What I need to do is select an item in a ListBox by ValueMember.
ASKER
private void listBoxRDOnly_DoubleClick( object sender, System.EventArgs e)
{
//get ID
int tempAEID = ReturnListBoxSelectedValue (this.list BoxRDOnly) ;
//navigate to first tab
this.tabControlAETabPages. SelectedTa b = this.tabPageManageAE;
//check Active filter if it is unchecked
if(!this.checkBoxShowActiv e.Checked)
{
this.checkBoxShowActive.Ch ecked = true;
}
//refresh list box
RefreshAEPOOLList();
//programmatically pic the AE ID
this.listBoxAEtoManage.Sel ectedValue = tempAEID;
}
This code works....but the last line HIGHLIGHTS the right ITEM......but it does not function like a MOUSE CLICK....the Selected Index Changed event does not fire.
{
//get ID
int tempAEID = ReturnListBoxSelectedValue
//navigate to first tab
this.tabControlAETabPages.
//check Active filter if it is unchecked
if(!this.checkBoxShowActiv
{
this.checkBoxShowActive.Ch
}
//refresh list box
RefreshAEPOOLList();
//programmatically pic the AE ID
this.listBoxAEtoManage.Sel
}
This code works....but the last line HIGHLIGHTS the right ITEM......but it does not function like a MOUSE CLICK....the Selected Index Changed event does not fire.
You can use ListBox.SetSelected(index, true). For example
private void listBoxRDOnly_DoubleClick( object sender, System.EventArgs e)
{
//get ID
int tempAEID = ReturnListBoxSelectedValue (this.list BoxRDOnly) ;
//navigate to first tab
this.tabControlAETabPages. SelectedTa b = this.tabPageManageAE;
//check Active filter if it is unchecked
if(!this.checkBoxShowActiv e.Checked)
{
this.checkBoxShowActive.Ch ecked = true;
}
//refresh list box
RefreshAEPOOLList();
//programmatically pic the AE ID
//find the index of selected item in list
int index = listBoxAEtoManage.Items.In dexOf(temp AEID);
// set selected for list box
this.listBoxAEtoManage.Set Selected(i ndex, true);
}
private void listBoxRDOnly_DoubleClick(
{
//get ID
int tempAEID = ReturnListBoxSelectedValue
//navigate to first tab
this.tabControlAETabPages.
//check Active filter if it is unchecked
if(!this.checkBoxShowActiv
{
this.checkBoxShowActive.Ch
}
//refresh list box
RefreshAEPOOLList();
//programmatically pic the AE ID
//find the index of selected item in list
int index = listBoxAEtoManage.Items.In
// set selected for list box
this.listBoxAEtoManage.Set
}
ASKER
Noted....thanks!
ASKER
private void listBoxRDOnly_DoubleClick(
{
//get ID
int tempAEID = ReturnListBoxSelectedValue
//navigate to first tab
this.tabControl1.SelectedT
//check Active filter if it is unchecked
if(!this.checkBoxShowActiv
{
this.checkBoxShowActive.Ch
}
//refresh list box
RefreshAEPOOLList();
//programmatically pic the AE ID //////////////////////////
}