Can't find what you're looking for?

Contact us or post in our forums and we'll help you find an answer.

Print Only Fully Visible Columns in FlexGrid

Background:

When printing a FlexGrid using the PrintGrid method, there is no option in the PrintGridFlags overload to print only fully visible columns. As a workaround, you can use the below approach to achieve this functionality.

Get the number of columns visible on the form, then take them into another FlexGrid and use the PrintGrid method, which can be accomplished by following the code below:

int formWidth = this.Width - System.Windows.Forms.SystemInformation.VerticalScrollBarWidth - c1FlexGrid1.Margin.Left;
int sumWidth = 0;
int cols = 0;
for (int i = 0; i < c1FlexGrid1.Cols.Count; i++)
  {
  sumWidth = sumWidth + c1FlexGrid1.Cols[i].WidthDisplay;
  if (sumWidth <= formWidth)
    {
    cols += 1;
    }
  else{
  break;
  }
}
C1FlexGrid grid = new C1FlexGrid();
grid.Cols.Count = cols;
grid.Rows.Count = c1FlexGrid1.Rows.Count;
for (int i = 1; i < cols; i++)
  {
  grid.Cols[i].Caption = grid.Cols[i].Name = c1FlexGrid1.Cols[i].Caption;
  grid.Cols[i].DataType = c1FlexGrid1.Cols[i].DataType;
  }
  for (int i = 1; i < c1FlexGrid1.Rows.Count; i++)
  {
    for (int j = 1; j < cols; j++)
    {
      grid[i, j] = c1FlexGrid1[i, j];
    }
  }
  grid.PrintGrid("fdmoe", PrintGridFlags.ShowPreviewDialog);
}

Get the Latest Version of C1
Download the Free Trial Now