Combo box + string grid

Hi...i have rarely used a combo box (once i think!) and was wondering how to do the following:

put a column from a stringgrid (i.e the name column) into a combo box...and then when an item is selected from the combobox it scrolss down to where the row is, but doesnt change the order or anythign!

Hope it's simple...one of the last things to do on my project!

Cheers guys
Laura xxx

Comments

  • : Hi...i have rarely used a combo box (once i think!) and was wondering how to do the following:
    :
    : put a column from a stringgrid (i.e the name column) into a combo box...and then when an item is selected from the combobox it scrolss down to where the row is, but doesnt change the order or anythign!
    :
    : Hope it's simple...one of the last things to do on my project!
    :
    : Cheers guys
    : Laura xxx
    :
    That's quite simple. To copy a column from a stringgrid to a combobox, use this line of code:
    [code]
    ComboBox1.Items.Assign(StringGrid1.Columns[i]);
    [/code]
    where i is an integer specifing, which column would want to have in the combobox.
    The next step is equally easy. The precise code depends on the ComboBox1.Sorted property. If it is FALSE, then the code becomes:
    [code]
    StringGrid1.Row:=ComboBox1.ItemIndex;
    [/code]
    And if it is TRUE:
    [code]
    StringGrid1.Row:=StringGrid1.Columns[i].IndexOf(ComboBox1.Text);
    [/code]
    Both these codes work best if the ComboBox1.Style is set to "csDropDownList". All the mentioned ComboBox properties can be found in the Object Inspector.
  • what happens if the choice selected in the combobox does not appear in the first column of the string grid (i.e. its in column 3)? and is it possible to search within the string grid for 2 values (selected in comboboxes) at the same time e.g. searching for a BURGER that is LARGE sized?

  • : what happens if the choice selected in the combobox does not appear in the first column of the string grid (i.e. its in column 3)? and is it possible to search within the string grid for 2 values (selected in comboboxes) at the same time e.g. searching for a BURGER that is LARGE sized?
    :
    :
    You can search the entire grid using a 2 nested for-do loops (1 for the columns, and 1 for the rows).
    Sure you can search for two values, as long as those two values can be optained individually. It requires 2 if-then statements in the 2 previously mentioned loops, 1 for the first word and 1 for the second. You keep the two coordinates in two different sets of variables.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories