JasonUSA
2016-09-19T11:27:36Z
Good morning,

Is it possible to have a combobox in the Parent Row of a grid? I would like to achieve something along the lines of that shown in the attached image and described here. The combobox in the Parent Row will not be associated with a column heading. In my example it will represent "Product Type". When the user chooses a Product Type a child row is added below this Parent Row. The Child Row will contain comboboxes that are associated with the column headings: Item Type & Item Color. When the user picks an option in one of these another Child Row will be added immediately below this with the same comboboxes so they can add another Item Type within the current Product Type. At the time a Product Type is defined, another Product Type Parent Row will be added allowing the user to define the Item Types and Item Colors within this Product Type.

I have been able to add the Parent Rows & Child Rows along with comboboxes in the Child Rows using .Columns.Add & .AddCol but have not been able to figure out how to add a combobox to a Parent Row.

Could you advise if this is possible and a potential solution please?

Untitled.png

Click to View Image83 View(s)



Thank you in advance and regards,

Jason.
Igor/10Tec
2016-09-20T07:10:57Z
Every group row in iGrid is in fact a normal cell - though it spans from the left to the right edge of the cell area. This cell is stored in the so-called row text column. This column can be accessed using the index returned by the RowTextCol property of iGrid.

Knowing this, I have just created a grid like the one on your picture:

Group rows with combo.png

Click to View Image72 View(s)



The source code:

With iGrid1
   .ShowControlsInAllCells = True

   With .Combos.Add("cbo")
      .AddItem "Item 1"
      .AddItem "Item 2"
      .AddItem "Item 3"
   End With
   
   .ColCount = 3
   
   .AddRow bGroupRow:=True
   .CellType(.RowCount, .RowTextCol) = igCellCombo
   .CellCtrlKey(.RowCount, .RowTextCol) = "cbo"
   .AutoHeightRow .RowCount
   
   .AddRow btLevel:=1
   .AddRow btLevel:=1
   
   .AddRow bGroupRow:=True
   .CellType(.RowCount, .RowTextCol) = igCellCombo
   .CellCtrlKey(.RowCount, .RowTextCol) = "cbo"
   .AutoHeightRow .RowCount
   
   .AddRow btLevel:=1
   .AddRow btLevel:=1
End With


Apparently, we can optimize this code if we use column default cells to initialize cells in our columns, including the row text column. We can also set the required default row height before we add rows because all rows will contain combo lists. Thus, our code can be transformed into this:


With iGrid1
   .ShowControlsInAllCells = True

   With .Combos.Add("cbo")
      .AddItem "Item 1"
      .AddItem "Item 2"
      .AddItem "Item 3"
   End With
   
   .ColCount = 3
   
   With .ColDefaultCell(.RowTextCol)
      .eType = igCellCombo
      .sCtrlKey = "cbo"
   End With
   
   .DefaultRowHeight = .GetOptimalCellHeight(bComboButton:=True)

   .AddRow bGroupRow:=True
   
   .AddRow btLevel:=1
   .AddRow btLevel:=1
   
   .AddRow bGroupRow:=True
   
   .AddRow btLevel:=1
   .AddRow btLevel:=1
End With


JasonUSA
2016-09-20T11:29:09Z
Thank you, Igor. This is great. Your explanation made the code snippet very easy to interpret.

While the layout of the grid is exactly what I was looking for, it appears that, on my PC at least, the value in the comboboxes within the Group Rows cannot be changed.

After pasting your code into my workbook and running as is, the comboboxes do not show a value and clicking on them does not display the list of options. I added ".CellValue" to your code and this displayed the value at that index in your ".Combos.Add("cbo")" definition but they still couldn't be changed:


With iGrid1
   .ShowControlsInAllCells = True

   With .Combos.Add("cbo")
      .AddItem "Item 1", vItemValue:=1
      .AddItem "Item 2", vItemValue:=2
      .AddItem "Item 3", vItemValue:=3
   End With
   
   .ColCount = 3
   
   .AddRow bGroupRow:=True, lHeight:=40
   .CellType(.RowCount, .RowTextCol) = igCellCombo
   .CellCtrlKey(.RowCount, .RowTextCol) = "cbo"
   'I ADDED THE BELOW LINE
   .CellValue(.RowCount, .RowTextCol) = 2
   
   .AddRow btLevel:=1, lHeight:=40
   .AddRow btLevel:=1, lHeight:=40
   
   .AddRow bGroupRow:=True, lHeight:=40
   .CellType(.RowCount, .RowTextCol) = igCellCombo
   .CellCtrlKey(.RowCount, .RowTextCol) = "cbo"
   'I ADDED THE BELOW LINE
   .CellValue(.RowCount, .RowTextCol) = 3
   
   .AddRow btLevel:=1, lHeight:=40
   .AddRow btLevel:=1, lHeight:=40
End With


If it hints at what may be going on, a single click on the combobox did nothing but a double-click contracted the Child Rows within the Group.

The following is your code built into my own project. Still very basic at the moment but getting there. This adds 2 Group Rows with comboboxes and, underneath each of these, 2 Child Rows 2 columns wide with a combobox in each cell.

The comboboxes in the cells in the Child Rows behave as you would expect where I'm able to change the value, but the comboboxes in the Group Rows do not.

Do you have any ideas why this might be the case?

With iGrid1
    .ShowControlsInAllCells = True

    With .Combos.Add("Tasks")
       .AddItem "Bridal Bouquet", vItemValue:=1
       .AddItem "Bridesmaid Bouquet", vItemValue:=2
       .AddItem "Boutonniere", vItemValue:=3
    End With
    
    With .Combos.Add("ItemTypes")
       .AddItem "Anemone", vItemValue:=1
       .AddItem "Daffodil", vItemValue:=2
       .AddItem "Poppy", vItemValue:=3
    End With
    
    With .Combos.Add("ItemColors")
       .AddItem "Blue", vItemValue:=1
       .AddItem "Green", vItemValue:=2
       .AddItem "Red", vItemValue:=3
    End With
    
    With .AddCol()
        .eType = igCellCombo
        .sCtrlKey = "ItemTypes"
        .vValue = 1
    End With
    
    With .AddCol()
        .eType = igCellCombo
        .sCtrlKey = "ItemColors"
        .vValue = 1
    End With
    
    .ColHeaderText(1) = "Item Type"
    .ColHeaderText(2) = "Item Color"
    
    .AutoWidthCol 1
    .AutoWidthCol 2
    
    .Header.AutoHeight
    
    .AddRow bGroupRow:=True, lHeight:=40
    .CellType(.RowCount, .RowTextCol) = igCellCombo
    .CellCtrlKey(.RowCount, .RowTextCol) = "Tasks"
    .CellValue(.RowCount, .RowTextCol) = 1
    
    Dim lParentRowIndex As Long
    lParentRowIndex = .RowCount
    
    .AddRow lHeight:=40, vRowParent:=lParentRowIndex
    .AddRow lHeight:=40, vRowParent:=lParentRowIndex
    
    .AddRow bGroupRow:=True, lHeight:=40
    .CellType(.RowCount, .RowTextCol) = igCellCombo
    .CellCtrlKey(.RowCount, .RowTextCol) = "Tasks"
    .CellValue(.RowCount, .RowTextCol) = 2
    
    lParentRowIndex = .RowCount
    
    .AddRow lHeight:=40, vRowParent:=lParentRowIndex
    .AddRow lHeight:=40, vRowParent:=lParentRowIndex
End With


Also, I'd like to ask one more question related to this but can do so in a new forum thread if needs be: I would like to have a Quantity field associated with the combobox in the Group Row, is there any way of achieving this? I appreciate that the idea of a Group Row is that it spans the width of the grid so probably not, but it would be useful if possible. If not, could the first row within each Group have a different definition than all subsequent rows? In my example I'd have a Group Row where the Task is defined and the row immediately after this would be for entering the number of Tasks and then every subsequent row would be for defining the ItemTypes & ItemColors. For example, either of the following outcomes:

Untitled.png

Click to View Image72 View(s)



Thank you very much,

Jason.
Henrik
2016-09-21T12:23:28Z
Jason,

Have you set AllowGroupRowEditing to True? I believe it is False per default.

/Henrik
JasonUSA
2016-09-21T12:52:16Z
Originally Posted by: Henrik 

Have you set AllowGroupRowEditing to True? I believe it is False per default.



Hi Henrik,

I have not but will try that this evening and let you know the outcome.

Thank you,

Jason.

Igor/10Tec
2016-09-21T15:08:51Z
Guys, you are right. Set AllowGroupRowEditing to True to make combo boxes in group rows "responsive". Group rows are not editable by default because in the vast majority of cases a double-click should collapse/expand them instead of starting editing.

Originally Posted by: JasonUSA 

I'd like to ask one more question related to this but can do so in a new forum thread if needs be: I would like to have a Quantity field associated with the combobox in the Group Row



Yes, in the future, please, ask one question per thread.

As for your problem, you can't add other cells to group rows, so you need to implement the 2nd layout. Fortunately, you can do it with iGrid easily as it allows you to add normal rows at any place.

JasonUSA
2016-09-21T16:07:05Z
Originally Posted by: Igor/10Tec 

As for your problem, you can't add other cells to group rows, so you need to implement the 2nd layout. Fortunately, you can do it with iGrid easily as it allows you to add normal rows at any place.



Wonderful - thank you for confirming. I converted iGrid600_10Tec.chm to .pdf & printed this morning and will read it with the hope of being able to answer most of my future questions.

Thanks again,

Jason.
JasonUSA
2016-09-21T22:22:05Z
Originally Posted by: JasonUSA 

Originally Posted by: Henrik 

Have you set AllowGroupRowEditing to True? I believe it is False per default.



Hi Henrik,

I have not but will try that this evening and let you know the outcome.

Thank you,

Jason.



That did the job - thank you.