The GridControl will have two columns: one for input names, and one for values.
The columns widths should be stretched so that the second column fills any extra space if the form is wide.
I also want to have an extra row at the bottom where I set its height to fill any extra vertical space in the form.
I have pasted sample code for my form below, but it is not behaving as I would expect. As I resize the form, the GridControl occasionally shows the vertical or horizontal scrollbar when it should not be shown. I only want to show the horizontal scrollbar if the form width is less than the width of my two columns. Likewise I only want to show the vertical srollbar if my form height is less than the height of my first 10 rows.
Can you please take a look and see why the scrollbars are occasionally appearing when the form is resized?
Also, I'd like to know what I need to do so that the cells cannot be highlighted (for example dragging from the top leftmost cell down and to the right, highlights a bunch of cells).
Thanks for your help.
using System.Drawing;
using System.Windows.Forms;
using Syncfusion.Windows.Forms.Grid;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
gridControl1.BeginUpdate();
InitGrid();
InitGridData();
ResizeGrid();
gridControl1.EndUpdate();
this.Resize += Form1_Resize;
}
void Form1_Resize(object sender, EventArgs e)
{
gridControl1.BeginUpdate();
ResizeGrid();
gridControl1.EndUpdate();
}
private const int NumInputs = 10;
private void InitGrid()
{
gridControl1.CurrentCellActivating += GridControl_CurrentCellActivating;
gridControl1.Dock = DockStyle.Fill;
gridControl1.HScrollPixel = true;
gridControl1.VScrollPixel = true;
gridControl1.ShowColumnHeaders = false;
gridControl1.ShowRowHeaders = false;
gridControl1.ColCount = 2;
gridControl1.RowCount = NumInputs + 1;
gridControl1.TableStyle.ReadOnly = true;
gridControl1.TableStyle.WrapText = false;
gridControl1.BorderStyle = BorderStyle.None;
gridControl1.ResizeColsBehavior = GridResizeCellsBehavior.None;
gridControl1.ResizeRowsBehavior = GridResizeCellsBehavior.None;
gridControl1.BackColor = Color.FromArgb(187, 212, 246);
for (int i = 1; i <= gridControl1.RowCount; i++)
for (int j = 1; j <= gridControl1.ColCount; j++)
gridControl1[i, j].Borders.All = new GridBorder(GridBorderStyle.None);
}
private void InitGridData()
{
for (int i = 1; i <= NumInputs; i++)
{
gridControl1[i, 1].Text = "Input " + i + ":";
gridControl1[i, 1].Font.Bold = true;
gridControl1[i, 2].Text = "Sample Value " + i;
}
}
private void ResizeGrid()
{
//get the columns to fill the entire grid.
//horizontal scrollbar should only appear if gridControl1.Width < gridControl1.ColWidths[1] + gridControl1.ColWidths[2])
gridControl1.Model.ColWidths.ResizeToFit(GridRangeInfo.Cols(1, 2));
if (gridControl1.Width > gridControl1.ColWidths[1] + gridControl1.ColWidths[2])
gridControl1.ColWidths[2] = gridControl1.Width - gridControl1.ColWidths[1];
//get the rows to fill the entire grid by adjusting the height of the filler row
//vertical scrollbar should only appear if gridControl1.Height < rowHeight
int rowHeight = 0;
for (int i = 1; i <= NumInputs; i++)
rowHeight += gridControl1.RowHeights[i];
if (gridControl1.Height <= rowHeight)
gridControl1.RowHeights[NumInputs + 1] = 0;
else
gridControl1.RowHeights[NumInputs + 1] = gridControl1.Height - rowHeight;
}
private void GridControl_CurrentCellActivating(object sender, GridCurrentCellActivatingEventArgs e)
{
if (e.ColIndex == 1 || e.RowIndex == gridControl1.RowCount)
e.Cancel = true;
}
}
}
What the form should look like when there is extra vertical and horizontal space (no scrollbars)
After resizing the form with my sample code, I see both horizontal and vertical scrollbars despite there being extra vertical and horizontal space