Author Topic: C# text boxes syncronising with list boxes  (Read 1869 times)

0 Members and 1 Guest are viewing this topic.

lanks

  • Guest
C# text boxes syncronising with list boxes
« on: August 30, 2007, 02:31:13 AM »
In my form i have 3 text boxes, and 3 list boxes. Text box one is linked to list box one, etc. the three list boxes are linked, but only the first list box contains unqiue items. an item from the first and second list box will tell you what item is needed from the third list box.

i am trying to do the following:
as the user types into any of the text boxes, their available options are narrowed down. (similar to a combo box)
i also wish to show the matching items from the other list boxes.

thank you in advance

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: C# text boxes syncronising with list boxes
« Reply #1 on: August 30, 2007, 02:52:19 AM »
One way is to use events, such as

Code: [Select]
private void textBox_TextChanged(object sender, EventArgs e)
as the user types in the textbox have the event update the listbox.
Here is a hack I did for updating a datagridview from a textbox

Code: [Select]
private void textBox1_TextChanged(object sender, EventArgs e)
    {
      try
      {
        string sSearch = this.textBoxSearch.Text.Trim();
        int iCnt = this.dataGridViewProductList.Rows.Count;
        for (int i = 0; i < iCnt; i++)
        {
          if (0 < sSearch.Length)
          {
            DataGridViewCell cell1 = this.dataGridViewProductList[1, i];
            string sCellval = Convert.ToString(cell1.Value);
            while (sCellval.Length < sSearch.Length)
            {
              sCellval += "\x0020";
            }
            string text3 = sCellval.Substring(0, sSearch.Length);
            if (string.Compare(sSearch, text3, true) == 0)
            {
              cell1.Selected = true;
              i = iCnt;
            }
          }
        }
      }
      catch
      {
        this.dataGridViewProductList.ClearSelection();
      }
    }