?
Solved

i keep forgetting this - Find List Box item by ValueMember not List Box Index

Posted on 2005-03-11
7
Medium Priority
?
507 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 13521884
For example:



private void listBoxRDOnly_DoubleClick(object sender, System.EventArgs e)
            {                  
                  //get ID
                  int tempAEID = ReturnListBoxSelectedValue(this.listBoxRDOnly);
                  //navigate to first tab
                  this.tabControl1.SelectedTab = 1;
                  //check Active filter if it is unchecked
                  if(!this.checkBoxShowActive.Checked)
                  {
                        this.checkBoxShowActive.Checked = 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.

            }
            
0
 
LVL 13

Accepted Solution

by:
dungla earned 2000 total points
ID: 13522531
Use ListBox.SelectedValue (object) and cast to your prefer datatype.

private void listBoxRDOnly_DoubleClick(object sender, System.EventArgs e)
          {              
               //get ID
               int tempAEID = ReturnListBoxSelectedValue(this.listBoxRDOnly);
               //navigate to first tab
               this.tabControl1.SelectedTab = 1;
               //check Active filter if it is unchecked
               if(!this.checkBoxShowActive.Checked)
               {
                    this.checkBoxShowActive.Checked = 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.

          }
private int ReturnListBoxSelectedValue(ListBox lb)
{
if (lb.SelectedValue != null)
{return int.Parse(lb.SelectedValue.ToString());}
else { return 0;}
}
0
 
LVL 13

Expert Comment

by:dungla
ID: 13522537
private void listBoxRDOnly_DoubleClick(object sender, System.EventArgs e)
          {              
               //get ID
               int tempAEID = ReturnListBoxSelectedValue(this.listBoxRDOnly);
               //navigate to first tab
               this.tabControl1.SelectedTab = 1;
               //check Active filter if it is unchecked
               if(!this.checkBoxShowActive.Checked)
               {
                    this.checkBoxShowActive.Checked = 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;}
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 13536358
What I need to do is select an item in a ListBox by ValueMember.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 13539454
private void listBoxRDOnly_DoubleClick(object sender, System.EventArgs e)
{                  
      //get ID
      int tempAEID = ReturnListBoxSelectedValue(this.listBoxRDOnly);
      //navigate to first tab
      this.tabControlAETabPages.SelectedTab = this.tabPageManageAE;
      //check Active filter if it is unchecked
      if(!this.checkBoxShowActive.Checked)
      {
            this.checkBoxShowActive.Checked = true;
      }
      //refresh list box
      RefreshAEPOOLList();
      //programmatically pic the AE ID

      this.listBoxAEtoManage.SelectedValue = 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.
0
 
LVL 13

Expert Comment

by:dungla
ID: 13541047
You can use ListBox.SetSelected(index, true). For example

private void listBoxRDOnly_DoubleClick(object sender, System.EventArgs e)
{              
     //get ID
     int tempAEID = ReturnListBoxSelectedValue(this.listBoxRDOnly);
     //navigate to first tab
     this.tabControlAETabPages.SelectedTab = this.tabPageManageAE;
     //check Active filter if it is unchecked
     if(!this.checkBoxShowActive.Checked)
     {
          this.checkBoxShowActive.Checked = true;
     }
     //refresh list box
     RefreshAEPOOLList();
     //programmatically pic the AE ID

     //find the index of selected item in list
     int index = listBoxAEtoManage.Items.IndexOf(tempAEID);
     // set selected for list box
     this.listBoxAEtoManage.SetSelected(index, true);
}
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 13546137
Noted....thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question