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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridListControlCell : ResizeToFit for Column Header not working

Thread ID:

Created:

Updated:

Platform:

Replies:

89253 Aug 20,2009 03:05 PM UTC Oct 13,2009 02:59 PM UTC WinForms 27
loading
Tags: GridControl
Santosh U
Asked On August 20, 2009 03:05 PM UTC

Hi,

I have a GGC in which I am populating GridListControl to have multicolumn data.

I have uploaded an image in which I have highlighted the Column Headers names are getting wrapped. I want column to resize along with header name. I could achieve resizing the column along with data using ResizeToFit property but I am not able to achieve this for Column Headers.

Please help.
Thanks,
Santosh U



gridlistcontrolheadersize_58d8ca0a.JPG

Jisha Joy [Syncfusion]
Replied On August 21, 2009 05:45 AM UTC


Hi Santhosh,

Thank you for posting query to us.

You could handle TablecontrolCurrentCellShowingDropDown event of GridGroupingControl. Inside the event you could access the GridDropDownGridListControlCellRenderer and call ResizeToFit method. See the code:

GridCurrentCell cc = this.GridGroupingControl.TableControl.CurrentCell;

if(cc.Renderer.GetType().Equals(typeof(GridDropDownGridListControlCellRenderer)))

{

GridControl grid = ((GridDropDownGridListControlCellRenderer)cc.Renderer).ListControlPart.Grid;

grid.ColWidths.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.IncludeHeaders);

}


Regards,
Jisha

Santosh U
Replied On August 25, 2009 01:08 PM UTC

Hi,

I have done this but still I get the same results.
I guess what I was doing and you provided ultimately results in same, following is my code

cr.ListControlPart.Grid.ColWidths.ResizeToFit(GridRangeInfo.Cols(0, cr.ListControlPart.Grid.ColCount), GridResizeToFitOptions.IncludeHeaders);

Please help me with the same.

Regards,
Santosh U

Rajadurai C [Syncfusion]
Replied On August 26, 2009 01:30 PM UTC

Hi Santosh,

Thanks for your update.

Please try to set the AutoSizeColumns property to false before calling ResizeToFit method. Here is the code for your reference.

cr.ListControlPart.AutoSizeColumns = false ;


Let me know if this serves your needs.

Regards,
Rajadurai

Santosh U
Replied On August 27, 2009 04:19 PM UTC

Hi Rajadurai,

Thanks for you update, I have tried that but I still get one of the column with header breaking in to multiple rows,

I have attached herewith a test project so that you can go through it and trouble shoot.


I have one more problem facing in this. In my actual application to show a drop down based on previous column value I am using CurrentCellShowingDropDown event. The event works fine but I see the dropdown for next time when I open it. I mean when I click for the very very first time I can not see the drop down (but the datasource is already applied and if I press UP | DOWN key it works. But to see the actual drop down I have to click thrice.
1. First time it brings the data but does not show the dropdown
2. Second time I guess it actual works to hide the drop down (which is the normal behaviour of a dropdown)
3. Third time it shows me the drop down.

You can see this kind of behaviour in the application which I have attached here with. First time when you click on drop down of last column (F_NO) it shows you drop down with shrinked size (please select countries from F_ID column). When you click again it will hide and when you again click for the third time It will show a fullsize drop down.

Due to this behaviour I guess I cant see the Dropdown for the first time at my end.

Please help me with this.
If you need any more details pls let me know

Thanks & Regards,
Santosh U



GGCAddNewRowTest_b07a943b.zip

Santosh U
Replied On August 28, 2009 02:07 PM UTC

Hi,

I have uploaded one project yesterday with two issues,
Today I am uploading the project with one more issue.

I have a GridListControl drop down (F_NO). I am setting its properties of DisplayMember and ValueMember but its not working, I mean it does not allow me to enter the data.

Could you please help me with the same.

Thanks,
Santosh U



GGCAddNewRowTest_8b52fc44.zip

Rajadurai C [Syncfusion]
Replied On August 28, 2009 02:39 PM UTC

Hi Santosh,

Thanks for your details.

Please try the following code which is a little modified one handled in TableControlCurrentCellShowingDropDown event.

GridGroupingControl ggc = gvTestCaseSteps;
GridCurrentCell gcc = e.TableControl.CurrentCell;
string CurrentColName = ggc.TableDescriptor.VisibleColumns[gcc.ColIndex - 1].Name.ToString();
if (CurrentColName == "F_NO")
{
GridDropDownGridListControlCellRenderer cr = (GridDropDownGridListControlCellRenderer)gcc.Renderer;
string valuetosend = ggc.Table.CurrentRecord.GetValue("F_ID").ToString();
//string valuetosend = "t" + id;
DataTable dt = dtvals(valuetosend);
cr.ListControlPart.Grid.BeginUpdate();
cr.ListControlPart.DataSource = dt;
cr.ListControlPart.AutoSizeColumns = false;
cr.ListControlPart.Grid.RowHeightEntries[0].Height = 30;
cr.ListControlPart.MinResizeColSize = 100;
cr.ListControlPart.Height = 400;
Size crSize = new Size();
crSize.Height = 500;
crSize.Width = this.Size.Width - 50;
cr.ListControlPart.MaximumSize = crSize;
cr.ListControlPart.Grid.ColWidths.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.IncludeHeaders);
cr.ListControlPart.Grid.EndUpdate();
cr.ListControlPart.Grid.Refresh();
}

Handle the same code snippet in CurrentCellActivated event. This solves the issue with wrapping of headers in first click on button.

Regarding the displaymember/valuemember issue, please check whether the name of the columns given were referring to MappingName of actual columns in datasource.

Let me know if you still faces any issue.

Regards,
Rajadurai

Santosh U
Replied On August 28, 2009 04:15 PM UTC

Hi Rajadurai,

The problem of the dropdown not showing on the first click has been resolve.

Regarding the value/display member.
1. I have two different datasources (obvious).
One for The actual grid
Another for The drop down

Please let me know if the column mapping name should be same as the datasource of the actual grid or should be of dropdown datasource db column??

Thanks,
Santosh U

Rajadurai C [Syncfusion]
Replied On August 31, 2009 12:41 PM UTC

Hi Santosh,

Thanks for your update.

In DisplayMember and ValueMember properties, you have to set the names of the columns which are actually present in the datasource which is binded to that dropdownlist. There is no need to refer to the columns of datasource of the maingrid.

The GridListControl is designed for read-only purpose. Hence it is not allowed to edit.

Please let me know if you have any further concerns.

Regards,
Rajadurai

Santosh U
Replied On September 5, 2009 06:33 AM UTC

Hi Rajadurai,

1. The column header size problem is still there.
2. Display value member:
Following is my code

Grid Column Name is "ReturnValue"
There are two columns in datasource RETURN_VALUE and DESCRIPTION
Following is the code which I am using either in Form load or Initialize components.


gcc1.TableDescriptor.Columns["ReturnValue"].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.GridListControl;
gcc1.TableDescriptor.Columns["ReturnValue"].Appearance.AnyRecordFieldCell.ValueMember = "RETURN_VALUE";
gcc1.TableDescriptor.Columns["ReturnValue"].Appearance.AnyRecordFieldCell.DisplayMember = "DESCRIPTION";
gcc1.TableDescriptor.Columns["ReturnValue"].Appearance.AnyRecordFieldCell.TextAlign = GridTextAlign.Left;
gcc1.TableDescriptor.Columns["ReturnValue"].Appearance.AnyRecordFieldCell.DropDownStyle = GridDropDownStyle.Editable;


Secondly on showing dropdown I am brining the data and applying to grid as follows.

// some code to get column name first
if (CurrentColName == "ReturnValue")
{
DataTable dt = getdata();
cr.ListControlPart.DataSource = dt;
//cr.ListControlPart.ValueMember = "RETURN_VALUE";
//cr.ListControlPart.DisplayMember = "DESCRIPTION";
}

Do let me know if anything going wrong in this since it does not show description after selecting it shows return_value of the dropdown.

Thanks,
Santosh

Rajadurai C [Syncfusion]
Replied On September 8, 2009 09:34 AM UTC

Hi Santosh,

I apologize for the delay caused in getting back to you.

1) The suggested workaround to handle the code of TableControlCurrentCellShowingDropDown event in TableControlCurrentCellActivated event will solve the issue with dropdownlist column header resizing. Please check with it.

2) When the DataSource, DisplayMember, ValueMember properties are set through Column' Appearance property, the GridStyleInfo object holds these properties for which the ValueMember refers to the actual location and DisplayMember refers to the column which has to be displayed in dropdownlist. Hence the following code,

gvTestCaseSteps.TableDescriptor.Columns["F_NO"].Appearance.AnyRecordFieldCell.DataSource = dtvals("t1");
gvTestCaseSteps.TableDescriptor.Columns["F_NO"].Appearance.AnyRecordFieldCell.ValueMember = "ID";
gvTestCaseSteps.TableDescriptor.Columns["F_NO"].Appearance.AnyRecordFieldCell.DisplayMember = "DVALUE";

works as said above.

If these properties were set through ListControlPart property, the ListControl actually handle these properties. According to ListControl, the ValueMember property is enough to set value in the cell. There is no need to use DisplayMember property. This is the behavior you have observed which is the actual functionality of ListControl.

Hence, the following code is enough to set value in dropdownlist, if datasource is binded through ListControlPart.

GridDropDownGridListControlCellRenderer cr = (GridDropDownGridListControlCellRenderer)gcc.Renderer;
string valuetosend = ggc.Table.CurrentRecord.GetValue("F_ID").ToString();
valuetosend = "t" + valuetosend;
DataTable dt2 = dtvals(valuetosend);
GridDropDownGridListControlPart list = cr.ListControlPart as GridDropDownGridListControlPart;
list.DataSource = dt2;
list.ValueMember = "ID";


Regards,
Rajadurai

Santosh U
Replied On September 10, 2009 01:51 PM UTC

Hi Rajadurai,

This is in reference with your code provided in this thread on

8/28/2009 10:39:40 AM

I could resolve this issue and it was working fine, suddenly this stopped working.
I just created a single function which gets called from both the events. Please let me know if this is ok ??

I have also tried without putting it into function still it is creating problem.

Secondly, I will try ur code regarding display and value member and let u know.

Thanks,
Santosh U

Santosh U
Replied On September 10, 2009 02:32 PM UTC

Hi,

I have tried ur code for Value and Display member, It is still giving problem to me. I am pasting the actual code of my project below.

ggcTestCaseSteps.TableDescriptor.Columns["EXP_RETURN_VALUE"].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.GridListControl;
//ggcTestCaseSteps.TableDescriptor.Columns["EXP_RETURN_VALUE"].Appearance.AnyRecordFieldCell.DataSource = dtBlankReturnValue();
ggcTestCaseSteps.TableDescriptor.Columns["EXP_RETURN_VALUE"].Appearance.AnyRecordFieldCell.ValueMember = "RETURN_VALUE";
ggcTestCaseSteps.TableDescriptor.Columns["EXP_RETURN_VALUE"].Appearance.AnyRecordFieldCell.DisplayMember = "DESCRIPTION";
ggcTestCaseSteps.TableDescriptor.Columns["EXP_RETURN_VALUE"].Appearance.AnyRecordFieldCell.TextAlign = GridTextAlign.Left;
ggcTestCaseSteps.TableDescriptor.Columns["EXP_RETURN_VALUE"].Appearance.AnyRecordFieldCell.DropDownStyle = GridDropDownStyle.Editable;


and below is the code which im calling in ggcTestCaseSteps_TableControlCurrentCellShowingDropDown and ggcTestCaseSteps_TableControlCurrentCellActivated.

private void FillGridDropdowns()
{
//GridGroupingControl ggcgrid = (GridGroupingControl)sender;
GridGroupingControl ggcgrid = ggcTestCaseSteps;
//GridGroupingControl ggcgrid = gvTestCaseSteps;
GridCurrentCell gcc = ggcgrid.TableControl.CurrentCell;
string CurrentColName = ggcgrid.TableDescriptor.VisibleColumns[gcc.ColIndex - 1].Name.ToString();
if (gcc.Renderer.ToString() == "GridDropDownGridListControlCellRenderer")
{
if (CurrentColName == "DATA_ID" || CurrentColName == "EXP_RETURN_VALUE")
{
GridDropDownGridListControlCellRenderer cr = (GridDropDownGridListControlCellRenderer)gcc.Renderer;
//GridDropDownCellRenderer cr = (GridDropDownCellRenderer)gcc.Renderer;
if (ggcgrid.Table.CurrentRecord.GetValue("STEP_ID") != null)
{
int Step_id = Convert.ToInt32((ggcgrid.Table.CurrentRecord.GetValue("STEP_ID").ToString()));
DataTable dtExpectedValuesId = new DataTable();
if (CurrentColName == "DATA_ID")
{
dtExpectedValuesId = SQLHelper.GetTableDataByStepID(Step_id).Tables[0];
//DataTable dtExpectedValuesId = SQLHelper.getTableDataByTableName("Login").Tables[0];
//cr.ListControlPart.DataSource = dtExpectedValuesId;
cr.ListControlPart.ValueMember = "DATA_ID";
}
if (CurrentColName == "EXP_RETURN_VALUE")
{
dtExpectedValuesId = SQLHelper.SelectStepByIDForCombo(Step_id).Tables[1];
//cr.ListControlPart.DataSource = dtExpectedValuesId;
cr.ListControlPart.ValueMember = "RETURN_VALUE";
//cr.ListControlPart.DisplayMember = "DESCRIPTION";
}
GridDropDownGridListControlPart list = cr.ListControlPart as GridDropDownGridListControlPart;

cr.ListControlPart.Grid.BeginUpdate();
list.DataSource = dtExpectedValuesId;
//list.ValueMember = "RETURN_VALUE";
cr.ListControlPart.AllowResizeColumns = false;
cr.ListControlPart.Grid.RowHeightEntries[0].Height = 30;
cr.ListControlPart.MinResizeColSize = 100;
cr.ListControlPart.Height = 400;
Size crSize = new Size();
crSize.Height = 500;
crSize.Width = this.Size.Width - 50;
cr.ListControlPart.MaximumSize = crSize;
cr.ListControlPart.FillLastColumn = true;

cr.ListControlPart.Grid.ColWidths.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.IncludeHeaders);
//cr.ListControlPart.Grid.HScrollBehavior = GridScrollbarMode.Automatic;
cr.ListControlPart.Grid.EndUpdate();
cr.ListControlPart.Grid.Refresh();
}
else
{
MessageBoxAdv.Show("Please select Step Name First");
}
}
}
}


I am having both the problems mentioned in previous post.

Thanks,
Santosh U

Rajadurai C [Syncfusion]
Replied On September 11, 2009 10:49 AM UTC

Hi Santosh,

I have modified the sample with the details i provided in previous update along with some changes in the way of handling FillGridDropdowns() method in TableControlCurrentCellShowingDropDown and TableControlCurrentCellActivated event. Here it was attached for your reference.
http://files.syncfusion.com/samples/Grid.Windows/7.3.0.20/F89253.zip

In this sample, the reported issues were solved with the handled code.

Let me know if you have any further queries.

Regards,
Rajadurai

Santosh U
Replied On September 11, 2009 02:33 PM UTC

Hi Rajadurai,

As per your code I have done all the change in my code, but I still face the problem. I had to modify ur code a bit since I have two columns with GridListControl... following is my code...
Please check and let me know


void ggcTestCaseSteps_TableControlCurrentCellActivated(object sender, GridTableControlEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(cc.RowIndex, cc.ColIndex);
if (cc.Renderer is GridDropDownGridListControlCellRenderer && (style.TableCellIdentity.Column.Name == "DATA_ID" || style.TableCellIdentity.Column.Name == "EXP_RETURN_VALUE"))
{
if (e.TableControl.Table.CurrentRecord.GetValue("STEP_ID") != null)
FillGridDropdowns(style.TableCellIdentity.Column.Name, Convert.ToInt32(e.TableControl.Table.CurrentRecord.GetValue("STEP_ID")));
else
MessageBoxAdv.Show("Please select Step Name First");
}

}

void ggcTestCaseSteps_TableControlCurrentCellShowingDropDown(object sender, GridTableControlCurrentCellShowingDropDownEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(cc.RowIndex, cc.ColIndex);
if (cc.Renderer is GridDropDownGridListControlCellRenderer && (style.TableCellIdentity.Column.Name == "DATA_ID" || style.TableCellIdentity.Column.Name == "EXP_RETURN_VALUE"))
{
if (e.TableControl.Table.CurrentRecord.GetValue("STEP_ID") != null)
FillGridDropdowns(style.TableCellIdentity.Column.Name, Convert.ToInt32(e.TableControl.Table.CurrentRecord.GetValue("STEP_ID")));
}

}

private void FillGridDropdowns(string ColumnName, int Step_id)
{
GridGroupingControl ggcgrid = ggcTestCaseSteps;
GridCurrentCell gcc = ggcgrid.TableControl.CurrentCell;
GridDropDownGridListControlCellRenderer cr = (GridDropDownGridListControlCellRenderer)gcc.Renderer;
GridDropDownGridListControlPart list = cr.ListControlPart as GridDropDownGridListControlPart;
DataTable dtExpectedValuesId = new DataTable();
if (ColumnName == "DATA_ID")
{
dtExpectedValuesId = SQLHelper.GetTableDataByStepID(Step_id).Tables[0];
//cr.ListControlPart.ValueMember = "DATA_ID";
list.DataSource = dtExpectedValuesId;
list.ValueMember = "DATA_ID";
}
if (ColumnName == "EXP_RETURN_VALUE")
{
dtExpectedValuesId = SQLHelper.SelectStepByIDForCombo(Step_id).Tables[1];
//cr.ListControlPart.ValueMember = "RETURN_VALUE";
list.DataSource = dtExpectedValuesId;
list.ValueMember = "RETURN_VALUE";
}

list.DataSource = dtExpectedValuesId;
//list.ValueMember = "ID";

cr.ListControlPart.Grid.BeginUpdate();
cr.ListControlPart.AllowResizeColumns = false;
cr.ListControlPart.Grid.RowHeightEntries[0].Height = 30;
cr.ListControlPart.MinResizeColSize = 100;
cr.ListControlPart.Height = 400;
Size crSize = new Size();
crSize.Height = 500;
crSize.Width = this.Size.Width - 50;
cr.ListControlPart.MaximumSize = crSize;
cr.ListControlPart.FillLastColumn = true;

cr.ListControlPart.Grid.ColWidths.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.IncludeHeaders);
cr.ListControlPart.Grid.EndUpdate();
cr.ListControlPart.Grid.Refresh();


}


Thanks,
Santosh

Rajadurai C [Syncfusion]
Replied On September 14, 2009 10:00 AM UTC

Hi Santosh,

I was unable to see the reported issues in the modified sample which i provided in previous update. Can you please provide a modified sample in which issues can be reproduced? So that we can see them and work to provide a better solution. Also, I was unable to access the attached database, test.mdf initially. It would be fine, if you update us the modified one which can be accessed in grid without any exception getting thrown.

Regards,
Rajadurai

Santosh U
Replied On September 19, 2009 01:06 PM UTC

Hi Rajadurai,

Thanks for your post, I have noticed one very weired behavior of GGC. Last time also I had noticed but did not post anything. If I create a new GGC apply all properties which I need, everything starts working fine. Last time I had a problem of a new row was getting added once I select dropdown which was then solved when I created a new grid with same properties.

Regarding my first problem where the size of the Dropdown does not get resize as per data is got solved by recreating the grid.

Regarding my Dropdown (GridListControl) does not show DisplayMember is still there.

I have created almost actual scenario of my project and sending it to you!!. I have also attached the database with it.

Once u run the project, you select first the step name and then just go to Return Values column dropdown, u will see respective data populating from database. Now here when I try to select it does not work and neither it shows my description (display value) in grid.

Please help!!!
Thanks,
Santosh U



ggcdispvalmember_a477b988.zip

Rajadurai C [Syncfusion]
Replied On September 21, 2009 12:30 PM UTC

Hi Santosh,

I apologize for the inconvenience caused.

I was unable to retrieve the data from the attached database to grid. The data cannot be read from it in our side. Can you please provide the sql data you have used in your application, by converting to a dataset? I have to check with the handled data in your side as the issues had been solved with the sample i provided before.

Regards,
Rajadurai

Santosh U
Replied On September 25, 2009 02:57 PM UTC

Hi Rajadurai,

I would like to test this on actual scenario instead in datatable so I am sending you the scripts of the databases.

One is having the structure and another is having the data.

Please let me know if any more things are needed from my side.

Thanks,
Santosh U



ggctest_1e548fde.zip

Santosh U
Replied On October 1, 2009 01:01 PM UTC

I HOPE SOMEBODY IS ADDRESSING THIS ISSUE ??

Rajadurai C [Syncfusion]
Replied On October 1, 2009 02:45 PM UTC

Hi Santosh,

Sorry for the inconvenience caused.

We are still facing some issues while trying to bind the database to the sample. Please provide us a complete sample in which the binded sql data can be accessed in grid normally thereby reproducing the reported issues. It would be fine for us to see the issue and give solution at the earliest.

Regards,
Rajadurai

Santosh U
Replied On October 1, 2009 04:14 PM UTC

Hi Rajadurai,

I hope your are making change in the DAL.cs file to connect to the database and the database has values for few step ids only which are: 1,2,3,4,5.

I have again run this on someother Independent machine and its working fine.

Can u pls recheck and let me know.

Thanks,
Santosh

Rajadurai C [Syncfusion]
Replied On October 6, 2009 03:26 PM UTC

Hi Santosh,

Sorry for the delay in getting back to you.

We have tried to bind the database you provided with the grid. But it don't get binding. We can able to see the issue only with a working sample(displaying data in grid which is retrieved from binded database) which we request you to provide. The code settings handled in the application binded to database provided from our side would work with any database binded to grid.

Regards,
Rajadurai

Santosh U
Replied On October 7, 2009 08:57 AM UTC

Hi,

I want to know if the database is got created, If yes then can you provide me a sample to have GridListControl with Value and dispalay member shown in the same. In this case the populated data should be depended on some previous column data.

Please let me know asap if this is possible for u ?


thanks,
Santosh

Rajadurai C [Syncfusion]
Replied On October 8, 2009 01:21 PM UTC

Hi Santosh,

Sorry for the inconvenience caused. We are currently preparing the sample based on the requirement you mentioned in last update. We will update you the one on 13th October 2009.

Regards,
Rajadurai

Santosh U
Replied On October 8, 2009 04:29 PM UTC

Hi Rajadurai,

Thanks for your reply, I will await for your update.

Thanks,
Santosh U

Rajadurai C [Syncfusion]
Replied On October 9, 2009 12:14 PM UTC

Hi Santosh,

Thanks for your update. We will get back to you with sample on or before the specified timeline.

Regards,
Rajadurai

Rajadurai C [Syncfusion]
Replied On October 13, 2009 02:59 PM UTC

Hi Santosh,

Thanks for your patience.

Please refer to the following sample in which two columns in gridgroupingcontrol are set with celltype 'GridListControl'. The 'Sport' column is binded with the 'School' DataSource at runtime checking whether the first column value is not null. The workarounds handled in TableControlCurrentCellActivated and TableControlShowingDropDropDown events solves the issue with column resizing in dropdown.
http://files.syncfusion.com/samples/Grid.Windows/7.3.0.20/F89253a.zip

Also, the list saves the value of the column set in ValueMember property in FillGridDropdowns() method as said before.

Regards,
Rajadurai

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.

Warning Icon 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.Close Icon

;