Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combox moving and adding items to the top.

Status
Not open for further replies.

robUK2

Programmer
Mar 10, 2008
57
0
0
TH
Hello,

VS 2008

I am using a binding source that is bound to a dataset with one table called AddressBook.

The binding source is bound to a combo box.

The address book table consists of 2 columns (number, name). There will be no duplicate phone numbers, as if it is already in the combo box it will
just set it to index zero.

This is just a simple table as I want to display the recent phone numbers.

When someone enters a phone number it will add it to the combo box, and position the number as index 0 (most recent).

However, if the phone number is already stored, then it should move it to index 0.

So this just a simple combo box that displays the most recent calls that are made. Just like any mobile phone.

This is my code so far. However, I am having a problem with moving the item to the top. is there some way this could be done better.

Many thanks for any advice,

Steve

Code:
      //Item doesn't exist so add it and display as the first item
            if (!this.bsRedialedNumbers.Contains(this.txtDetails.Text))
            {
                DataRowView drv;
                drv = (DataRowView)this.bsRedialedNumbers.AddNew();
                drv["Name"] = this.txtDisplay.Text;
                drv["Number"] = this.txtDisplay.Text;
                
                //drv.EndEdit();
            }
            else //Item already exists so just move it to the top of the list.
            {
                //Move the item to the top of the combo box.
                DataRowView drv;
                drv = (DataRowView)this.bsRedialedNumbers;
                int index = this.bsRedialedNumbers.Find("Number", txtDetails.Text);       
            }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top