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.
Unfortunately, activation email could not send to your email. Please try again.

Resize to fit a Grid control column

Thread ID:

Created:

Updated:

Platform:

Replies:

78806 Jan 1,2009 07:06 AM Jan 13,2009 12:53 AM Windows Forms 6
loading
Tags: Tools
ali
Asked On January 1, 2009 07:06 AM

Hi,
I want to resize to fit the column width by longest text of that particular column when double clicking on the column header border (want to work as normal windows like grid).
plz help me out abt this.



Jisha Joy [Syncfusion]
Replied On January 2, 2009 12:42 AM


Hi Ali,

To resize to fit a particular range of cells (could be a row, col or table or several rows or whatever), you use the ResizeToFit method which is a member of the GridControl.ColWidths and GridControl.RowHeights classes.



So, to resize the widths of all cells in column 1, use



this.gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Col(1));





To resize the heights of the range (1,1) to (4,5), use



this.gridControl1.RowHeights.ResizeToFit( GridRangeInfo.Cells(1,1,4,5));




Please let me know if this helps.


Regards,
Jisha


ali
Replied On January 8, 2009 04:59 AM


Hi Jisha,

Thanks for your valuable reply.
I already tried this ResizeToFit method. and it was working. but i need to do this resize when double clicking on Column divider. for that in which event i should write the line of code.

thank again.


>
Hi Ali,

To resize to fit a particular range of cells (could be a row, col or table or several rows or whatever), you use the ResizeToFit method which is a member of the GridControl.ColWidths and GridControl.RowHeights classes.



So, to resize the widths of all cells in column 1, use



this.gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Col(1));





To resize the heights of the range (1,1) to (4,5), use



this.gridControl1.RowHeights.ResizeToFit( GridRangeInfo.Cells(1,1,4,5));




Please let me know if this helps.


Regards,
Jisha




Jisha Joy [Syncfusion]
Replied On January 9, 2009 05:38 AM

Hi Ali,

You can handle ResizingColumns event of GridControl and can check for the e.Reason. Please see the code:

this.gridControl1.ResizingColumns += new Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventHandler(gridControl1_ResizingColumns);



void gridControl1_ResizingColumns(object sender, Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventArgs e)
{
if(e.Reason == Syncfusion.Windows.Forms.Grid.GridResizeCellsReason.DoubleClick)
MessageBox.Show("Fired");
}

Regards,
Jisha


ali
Replied On January 12, 2009 04:35 AM

Hi Jisha,

Thank you for your support and help.
I have tried with the code wich u have mentioned earlier.

Here is my code

private void syncGrdCtrl1_ResizingColumns(object sender, GridResizingColumnsEventArgs e)
{
if (e.Reason == GridResizeCellsReason.DoubleClick)
{
syncGrdCtrl1.ColWidths.ResizeToFit(GridRangeInfo.Col(e.Columns.Left));
}
}

for getting the column Index i took the e.Columns.Left ( as well as the .Right).

the event is firing but the columns still remain without any change. I even tried with a fixed column Index (instead of e.Columns.Left, i have given 2).

Thanks,
Ali PP


>Hi Ali,

You can handle ResizingColumns event of GridControl and can check for the e.Reason. Please see the code:

this.gridControl1.ResizingColumns += new Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventHandler(gridControl1_ResizingColumns);



void gridControl1_ResizingColumns(object sender, Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventArgs e)
{
if(e.Reason == Syncfusion.Windows.Forms.Grid.GridResizeCellsReason.DoubleClick)
MessageBox.Show("Fired");
}

Regards,
Jisha




ali
Replied On January 12, 2009 05:20 AM

Hi Jisha..

Thanks for your suport.

finally i have done it..

here is my code

private void syncGrdCtrl1_ResizingColumns(object sender, GridResizingColumnsEventArgs e)
{
if (e.Reason == GridResizeCellsReason.DoubleClick)
{
int iColIndx = e.Columns.Left;
if (syncGrdCtrl1.ColWidths.IsDefault(iColIndx))
{
syncGrdCtrl1.ColWidths.ResizeToFit(GridRangeInfo.Col(iColIndx));
e.Cancel = true;
}
else
{
e.Cancel = false;
}
}
}

Thanks n Regards

Ali PP

>Hi Jisha,

Thank you for your support and help.
I have tried with the code wich u have mentioned earlier.

Here is my code

private void syncGrdCtrl1_ResizingColumns(object sender, GridResizingColumnsEventArgs e)
{
if (e.Reason == GridResizeCellsReason.DoubleClick)
{
syncGrdCtrl1.ColWidths.ResizeToFit(GridRangeInfo.Col(e.Columns.Left));
}
}

for getting the column Index i took the e.Columns.Left ( as well as the .Right).

the event is firing but the columns still remain without any change. I even tried with a fixed column Index (instead of e.Columns.Left, i have given 2).

Thanks,
Ali PP


>Hi Ali,

You can handle ResizingColumns event of GridControl and can check for the e.Reason. Please see the code:

this.gridControl1.ResizingColumns += new Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventHandler(gridControl1_ResizingColumns);



void gridControl1_ResizingColumns(object sender, Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventArgs e)
{
if(e.Reason == Syncfusion.Windows.Forms.Grid.GridResizeCellsReason.DoubleClick)
MessageBox.Show("Fired");
}

Regards,
Jisha






Jisha Joy [Syncfusion]
Replied On January 13, 2009 12:53 AM

Hi Ali,

Thank you for your update. Glad to hear that issue has been resolved.

Regards.
Jisha


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;