C1GanttView Set Grid Row Height in Code

Posted by: john.morrelles on 25 March 2021, 12:05 am EST

  • Posted 25 March 2021, 12:05 am EST

    I can change the row height of the rows in the grid portion of the gantt chart manually by clicking and dragging them. How do I set the row height in the grid in code?

    There's a rows collection on the C1FlexGrid and the row objects in that collection have Height and DisplayHeight properties, but changing those properties only appears to affect the column header row.

  • Replied 25 March 2021, 4:52 am EST

    I found a way to do it in the OwnerDrawCell event, but that leads to another question: how do I synchronize the height of the rows on the chart side of the control?
  • Replied 25 March 2021, 4:32 pm EST

    Hello John,

    The chart portion of the GanttView is also a FlexGrid control so you can also change the height of rows of it to synchronize the height of the rows on the chart side with the grid side.
    Please find the attached sample implementing the same.

    Prabhat Sharma.
  • Replied 26 March 2021, 2:59 am EST

    That works, but it looks like calling BeginUpdate and EndUpdate in a cell draw event is causing some issues. I changed it to call on just the GanttView control rather than both of the individual grid controls and it didn't help. I'm seeing either buttons on my form or the entire form itself becoming unresponsive with the Begin/EndUpdate calls.

    After changing the row height, I'm also seeing the predecessor lines failing to reconnect to their tasks.

    I think I may be able to work around the screen freezes by calling the Begin/EndUpdate in the code that triggers the cell draws. To address the predecessor arrow redraws, I may have to unload and reload the tasks, but I'm open to better suggestions.
  • Replied 29 March 2021, 2:51 am EST

    I'm not having any luck with getting the predecessor arrows to stay connected to their task bars.

    The predecessor links stay connected when the row heights are adjusted manually as seen in the attached screen cap.

    The supplied code (below) is being run in an owner draw event and that's the only place it works, which seems odd because there's nothing in the code that depends on the event parameters.

    C1FlexGrid grid = c1GanttView1.Controls[2] as C1FlexGrid;
    C1FlexGrid grid1 = c1GanttView1.Controls[0] as C1FlexGrid;

    for (int i = 0; i < grid.Rows.Count; i++)
    grid.Rows[i].HeightDisplay = 30;
    grid1.Rows[i].HeightDisplay = 30;

    I really need to be able to set row heights and have the predecessor arrows stay connected.
  • Marked as Answer

    Replied 29 March 2021, 5:23 pm EST

    Hello John,

    As the code snippet suggested in the last response is a workaround so it is possible that it will not work properly in every situation like predecessor lines failing to reconnect to tasks.

    The best way to change the row height is to set the Font of the GanttView and if you want all bar heights will be adapted accordingly to GanttView font then you can set the AdaptiveBarHeight property to true.

    If you want to change the font of the row/Column header then you can set the Fixed Font as per your need.

    c1GanttView1.Font = new Font("", 20);
    c1GanttView1.AdaptiveBarHeight = true;
    c1GanttView1.FixedFont = new Font("", 10);

    If you want to change the text size on the grid side then you can set the font of the FlexGrid in the OwnerDrawCell event.

    Prabhat Sharma.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels