We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Achieving similar behaviour to windows data grid

Hi Syncfusion Support,

Say for example I have a grid with two columns of width 100px. In a windows data grid if my grid was 300px wide then we automatically get an extra column that's unsortable and unmovable as the last column to fill in the gap.

With the syncfusion grid there is just a blank space the same colour as my grid background. Is it possible to easily achieve this default windows behaviour?

Thanks very much,
John


3 Replies

JJ Jisha Joy Syncfusion Team June 7, 2011 12:13 PM UTC

Hi John,

You could achieve the desired behavior by handling the TableControl.SizeChanged and QueryColWidth event. See the code:



int indentCols;
int parentIndentCols;

private void TableModel_QueryColWidth(object sender, GridRowColSizeEventArgs e)
{
GridTableModel gridModel = sender as GridTableModel;
GridTableControl grid = (GridTableControl)gridModel.ActiveGridView;

if (gridModel != null && grid != null)
{
int availableArea;
int VSBarSize = 0;
if (VScrollVisible)
VSBarSize = SystemInformation.VerticalScrollBarWidth;

indentCols = (gridModel.GetColumnIndentCount()) * grid.GroupingControl.TableOptions.IndentWidth;


if (e.Index > gridModel.Cols.HeaderCount + gridModel.GetColumnIndentCount() - 1)
{
parentIndentCols = VScrollVisible ? indentCols : indentCols - SystemInformation.VerticalScrollBarWidth;
availableArea = grid.GroupingControl.ClientSize.Width - indentCols - VSBarSize;
e.Size = (int)availableArea / (grid.TableDescriptor.VisibleColumns.Count);
e.Handled = true;
}

}
}


private bool VScrollVisible = false;
private void TableControl_SizeChanged(object sender, EventArgs e)
{
VScrollVisible = this.gridGroupingControl1.TableControl.VScroll;
GridTableControl tableControl = sender as GridTableControl;
tableControl.Invalidate();
}


Sample for your reference,

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GGC-1100757244.zip


Please let me know if this helps.

Regards,
Jisha



JT Johnathan Tunnicliffe June 7, 2011 02:56 PM UTC

Whilst that's ok, it doesn't really mimic what windows does. Windows introduces a new column that's unmovable and unsortable. When the normal columns take up the entire space this extra column doesn't exist. When the normal columns are bigger than the viewable area then we can scroll as normal and the extra column doesn't appear. When the total width of columns in view is smaller than the viewable area this extra column is there and takes up the remaining space.



JJ Jisha Joy Syncfusion Team June 14, 2011 03:45 AM UTC

Hi Johnathan,

Can you please provide us a sample showing the issue?. So that we could analyze it further.

Regards,
Jisha


Loader.
Live Chat Icon For mobile
Up arrow icon