in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Populating a C1ComboBox & Using at Grid Editor at runtime

Last post 06-26-2008 3:26 PM by C1_GregL. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-25-2008 6:03 AM

    Populating a C1ComboBox & Using at Grid Editor at runtime

    Hi,

    I have a need to have a dropdown in a FlexGrid cell that will contain a different amount of columns and data depending on the row that is selected.

    I am trying to populate a C1ComboBox in the grids BeforeEdit event and set it's Editor to be the C1ComboBox in the startedit event.

    The data I am populating from comes from an arraylist of strings which are tab seperated, so for each member of the arraylist I wind through and use AddItem to add them to the C1Combo. The code executes without error, only the C1Combo is always empy with a count of zero items.

    Can anyone help? am i doing something fundementally wrong?

     

    J.

  • 06-25-2008 10:26 AM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 516

    Re: Populating a C1ComboBox & Using at Grid Editor at runtime

    Have you set the data mode to AddItem?

    1. c1Combo1.DataMode = C1.Win.C1List.DataModeEnum.AddItem;
    2. c1Combo1.AddItemTitles("Name;Age;Location"); 
    3. c1Combo1.AddItemSeparator = '\t';
    4. c1Combo1.AddItem("Bob\t32\tPittsburgh");
    5. c1Combo1.AddItem("Chris\t45\tPittsburgh");

    Regards,
    Greg L

    Filed under: ,
  • 06-26-2008 4:13 AM In reply to

    Re: Populating a C1ComboBox & Using at Grid Editor at runtime

    Thanks Greg, that was it.

    Couple of questions though -

    1. If I declare the combo in code (as private to the form, in the form load event) it still doesn't work, but if I physically place a combo on the form it does? any ideas? It's not a big deal as I can just place one on the form.

    2. I populate the combo in the BeforeEdit Event, and set it to be the editor in the StartEdit event, but it's really clunky - I have to double click the cell to get the combo to appear. Is there a slicker way to do this, so the combo appears and drops as the cell is entered?

     

    Thanks,

     

    J.

  • 06-26-2008 3:26 PM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 516

    Re: Populating a C1ComboBox & Using at Grid Editor at runtime

    Hi J,

    1. What you can do here is add the C1Combo to the form dynamically before you add items to it.  I believe this is necessary due to C1Combo, not C1FlexGrid.

    1. C1Combo combo = new C1Combo();
    2. this.Controls.Add(combo);
    3. combo.Visible = false;

    2. To open the combo on cell focus, there are probably many events you could do this in; one is the grid's click event.  You can force the combo to drop down using C1FlexGrid.StartEditing and C1Combo.OpenCombo events

    1. private void c1FlexGrid1_Click(object sender, EventArgs e)
    2. {
    3.   if (c1FlexGrid1.Col == 1)
    4.   {
    5.    c1FlexGrid1.StartEditing(c1FlexGrid1.Row, 1);
    6.    C1Combo com = (C1Combo)c1FlexGrid1.Cols[1].Editor;
    7.    com.OpenCombo();
    8.   }
    9. }

    I would also check to see how many times BeforeEdit is being called in your app, because it may be raised repeatedly on one cell edit, and this could slow down your app loading the combo over and over again.

    hope that helps,
    Greg L

Page 1 of 1 (4 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.