Hi,
I previously made a post asking about the multiline display for a single row. It worked fine in my mini project. But now that i want to implement that feature into the main software, i get some weird behavior.
I found a work around to my problem by calling PerformAutoSize() 2 times to get the expected result, else it doesnt work. :(
foreach (UltraGridRow row in e.Layout.Rows.All){ row.PerformAutoSize();row.PerformAutoSize();}
Maybe you can see the problem already there but i will be adding codes that happen in the event InitializeLayout. I tried to get the most related lines of code. Here it is :
this.SuspendLayout(); this.BeginUpdate();
e.Layout.CaptionVisible = DefaultableBoolean.False; e.Layout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.None; e.Layout.Override.RowSelectors = DefaultableBoolean.False; e.Layout.Override.ActiveAppearancesEnabled = DefaultableBoolean.False; e.Layout.Bands[0].Override.AllowAddNew = AllowAddNew.No; e.Layout.Bands[0].Override.AllowDelete = DefaultableBoolean.False; e.Layout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False; this.DisplayLayout.Override.WrapHeaderText = DefaultableBoolean.True; e.Layout.Bands[0].Override.AllowRowLayoutCellSizing = RowLayoutSizing.Both; e.Layout.Bands[0].Override.CellClickAction = CellClickAction.CellSelect; e.Layout.Bands[0].Override.SelectTypeCell = SelectType.Extended; e.Layout.Override.HeaderClickAction = HeaderClickAction.Select; e.Layout.Override.SelectTypeCol = SelectType.None; e.Layout.Override.SelectedCellAppearance = e.Layout.Override.HotTrackHeaderAppearance; e.Layout.ScrollStyle = ScrollStyle.Immediate;
foreach (UltraGridColumn column in this.DisplayLayout.Bands[0].Columns) { if (column.Tag is IEntete) { IEntete entete = (IEntete)column.Tag; if (column.Width < entete.EnteteSource.TO.Largeur || entete.EnteteSource.TO.Largeur == column.MinWidth) column.RowLayoutColumnInfo.PreferredCellSize = new Size(entete.EnteteSource.TO.Largeur, column.RowLayoutColumnInfo.PreferredCellSize.Height); } }
this.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout;
e.Layout.Override.RowSizing = RowSizing.Free; foreach (UltraGridColumn column in e.Layout.Bands[0].Columns) { column.AutoSizeEdit = Infragistics.Win.DefaultableBoolean.True; column.CellMultiLine = Infragistics.Win.DefaultableBoolean.True; }
foreach (UltraGridRow row in e.Layout.Rows.All) { row.PerformAutoSize(); row.PerformAutoSize(); }
this.EndUpdate();this.ResumeLayout();
If you want more info on my problem, i can send more code. Note : I don't use any events that could interact with the UltraGrid other than the InitializeLayout.
What version of the grid are you using?
And in the code you have here, what is "this"? Is this an inherited grid control, or is this the form?
I don't see anything wrong with this code, so my best guess is that doing this in InitializeLayout is too early.
It's also not very efficient to loop through all of the rows in the grid, anyway. You might be better off calling PerformAutoSize in the InitializeRow event, or if you must loop, do it immediately after setting the DataSource/DataMember on the grid instead of inside InitializeLayout.
Hello, i use UltraGrid v10.2.
Here is a little project containing this behavior :
The MultiLine display works after editing the cells but not before, even by the 3 events i use.
If you dont have time to open this file, here is the main code :
public partial class Form1 : Form { public Form1() { InitializeComponent(); string[] test = new string[2]; test[0] = "test"; test[1] = "testtt eeee eeeeee eeeee ee"; this.ultraDataSource1.Rows.Add(true, test); } private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { this.ultraGrid1.SuspendLayout(); this.ultraGrid1.BeginUpdate(); this.ultraGrid1.DisplayLayout.Override.CellMultiLine = DefaultableBoolean.True; foreach (UltraGridCell cell in this.ultraGrid1.DisplayLayout.Rows[0].Cells) cell.CellDisplayStyle = CellDisplayStyle.FullEditorDisplay; this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout; e.Layout.Override.RowSizing = RowSizing.Free; foreach (UltraGridColumn column in e.Layout.Bands[0].Columns) column.AutoSizeEdit = Infragistics.Win.DefaultableBoolean.True; foreach (UltraGridRow row in e.Layout.Rows.All) { // For the PerformAutoSize() to works, you need to uncomments those 2. //row.PerformAutoSize(); row.PerformAutoSize(); } this.ultraGrid1.EndUpdate(); this.ultraGrid1.ResumeLayout(); } private void ultraGrid1_AfterColPosChanged(object sender, AfterColPosChangedEventArgs e) { foreach (UltraGridRow row in this.ultraGrid1.Rows.All) { //This line doesn't work. row.PerformAutoSize(); } } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { //This line doesnt work. Adding more PerformAutoSize() won't work either. e.Row.PerformAutoSize(); } }
I ran your sample and I get the same results you describe.
I think the problem here is that you are forcing the creation of cells inside the InitializeLayout event. Setting CellDisplayStyle isn't the problem (especially since you are setting it to the default value, anyway). If I change your code to set any property on the cell, the same thing happens.
So I think the problem here is that you are referencing cells at all inside the InitializeLayout. This is forcing the cells to be created too early, and I strongly advise against this. InitializeLayout is intended to allow you to set up the layout of the grid. It's generally not a good idea to reference anything on the rows or cells from within this event - that's what InitializeRow is for.
Why set CellDisplayStyle on the individual cells and set it to the default value, anyway? Are you really going to have cells in the same column with different CellDisplayStyle settings? If so, you should be using the InitializeRow event to set it.
Hello,
If this is forcing the cells to be created too early, why no exception?I looked in the infragistic documentation and they are using BOTH RowLayoutStyle and CellDisplayStyle inside the InitializeLayout event. Even modifying a cell !!!! Word for word from the documentation!!! "// It can be also set on an individual cell." Here are the links : http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~CellDisplayStyle.htmlhttp://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/HTML/Infragistics2.Win.UltraWinGrid.v11.1~Infragistics.Win.UltraWinGrid.UltraGridBand~RowLayoutStyle.html
// It can be also set on an individual cell."
Even if i don't touch the cells, I still get the same problem with this : this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout;
I dont get my multiline, is the RowLayoutStyle needed in InitializeRow??It is similar to what is inside the documentation. Why not working? And here is the code :
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { this.ultraGrid1.SuspendLayout(); this.ultraGrid1.BeginUpdate(); this.ultraGrid1.DisplayLayout.Override.CellMultiLine = DefaultableBoolean.True; this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout; e.Layout.Override.RowSizing = RowSizing.Free; this.ultraGrid1.EndUpdate(); this.ultraGrid1.ResumeLayout(); } private void ultraGrid1_AfterColPosChanged(object sender, AfterColPosChangedEventArgs e) { foreach (UltraGridRow row in this.ultraGrid1.Rows.All) { //This line doesnt work. row.PerformAutoSize(); } } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { //This line doesnt work. e.Row.PerformAutoSize(); } }In our application, the UltraGrid is a Pivot Table and it support different layers of header for each column or combination of column. Some will contain image or buttons for specific operations. And we got a few reports containing hundreds of rows for lots of columns (based on date), and to speed up loading we set the cells to PlainText.
Thanks!
Luke111 said:If this is forcing the cells to be created too early, why no exception?
I don't think this is something we could catch with an exception, and it's not necessarily an invalid thing to do in every case.
Luke111 said:I looked in the infragistic documentation and they are using BOTH RowLayoutStyle and CellDisplayStyle inside the InitializeLayout event. Even modifying a cell !!!! Word for word from the documentation!!! "// It can be also set on an individual cell." Here are the links : http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~CellDisplayStyle.htmlhttp://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/HTML/Infragistics2.Win.UltraWinGrid.v11.1~Infragistics.Win.UltraWinGrid.UltraGridBand~RowLayoutS
Clearly the problem here is being caused by the combination of both settings, not just one by itself.
Luke111 said:Even if i don't touch the cells, I still get the same problem with this : this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout;
Are you saying that if you download the sample you attached here and remove the code that loops through the cells, it still doesn't size the row properly?
I tried it again just to make sure and it works fine for me. So if that is not working for you, then my only suggestion is that you make sure you have the latest service release.
How to get the latest service release - Infragistics Community
Luke111 said:I dont get my multiline, is the RowLayoutStyle needed in InitializeRow??
As a general rule, the RowLayoutStyle, or any property that applies to a column, band, or override should be applied in InitializeLayout.
Properties that affect individual rows or cells are better set in the InitializeRow event.
Luke111 said: It is similar to what is inside the documentation. Why not working? And here is the code : private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { this.ultraGrid1.SuspendLayout(); this.ultraGrid1.BeginUpdate(); this.ultraGrid1.DisplayLayout.Override.CellMultiLine = DefaultableBoolean.True; this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout; e.Layout.Override.RowSizing = RowSizing.Free; this.ultraGrid1.EndUpdate(); this.ultraGrid1.ResumeLayout(); } private void ultraGrid1_AfterColPosChanged(object sender, AfterColPosChangedEventArgs e) { foreach (UltraGridRow row in this.ultraGrid1.Rows.All) { //This line doesnt work. row.PerformAutoSize(); } } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { //This line doesnt work. e.Row.PerformAutoSize(); } }
It is similar to what is inside the documentation. Why not working? And here is the code :
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { this.ultraGrid1.SuspendLayout(); this.ultraGrid1.BeginUpdate(); this.ultraGrid1.DisplayLayout.Override.CellMultiLine = DefaultableBoolean.True; this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout; e.Layout.Override.RowSizing = RowSizing.Free; this.ultraGrid1.EndUpdate(); this.ultraGrid1.ResumeLayout(); } private void ultraGrid1_AfterColPosChanged(object sender, AfterColPosChangedEventArgs e) { foreach (UltraGridRow row in this.ultraGrid1.Rows.All) { //This line doesnt work. row.PerformAutoSize(); } } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { //This line doesnt work. e.Row.PerformAutoSize(); } }
I tried replacing the code in your sample with this code, and now I see the same problem without accessing the cells. This seems like a bug to me, so I am going to send the modified sample over to Infragistics Developer Support so they can write this up for developer review and get it looked into.
Thx! Happy to hear we found a bug :D
Hi Luke,
I just wanted to let you know that we found the bug and it will be fixed in the next service release scheduled for November (after the release of NetAdvantage 11.2).
But also, while fixing this, we discovered that it works fine if you set RowSizing to AutoFree instead of Free. In fact, even with the fix, using AutoFree will be better (slightly more efficient) than using Free, anyway.