Hi all,I have written an extender for the UltraGrid in order to validate some data for our company.The extender inserts columns into the grid providing an index and a key, nothing special so far.
When I attach the extender to a default grid everything works fine.
Now when RowLayoutStyle of the grid is set to ColumnLayout the inserted columns seem to get merged/overlapped with the existing column at the index-position where the column was inserted.It seems to replace the column at the specific index.
I figured out that this has something to do with the RowLayout / RowLayoutColumnInfo from the original column beeing applied to the inserted column, but somehow I can not sort it out any further.Inserting at the end works, but it is unfortunately not an option.
How can I insert a column when ColumnLayout is active? Is there a way to add new Columns together with RowLayoutInfo or something like this?How can this be done in a "nice, programmatical way"?
Any hints are kindly appreciated,best regardsAndy
Hi Andy,
It's hard to say what's happening here without seeing what code you are using to insert the column and what your ColumnLayout looks like.
Basically, the way ColumnLayouts work is that if a column has RowLayoutColumnInfo settings like OriginX and OriginY, these settings determine the position of the column and the Header.VisiblePosition has no effect. The VisiblePosition is overridden by the ColumnLayout.
So I suspect that your insert code is setting the VisiblePosition on the column, but it really needs to set the RowLayoutColumnInfo properties like OriginX, OriginY, SpanX, and SpanY.
What you set these to is too complicated to explain in a forum post, but you might want to search around for some information on the concept of a GridBagLayout and how these properties work. Or take a look at the existing RowLayoutColumnInfo properties on the existing columns. OriginX and OriginY are pretty intuitive once you get the general sense of how they work.
Hi Mike,thanks for the explanation. If I got that right I need to handle the OriginX/Y and SpanX/Y for a newly added column in order to diplay the new column correctly when a ColumnLayout is in place.
This is one of the functions I use to add a Button-Column, where xxx is a Configuration class that stores a reference to the grid together with an existing column-name that is used to determine the index for the column to be added.
protected virtual void AddOptionColumn() { if (_ugvhConfig.Grid.DisplayLayout.Bands[0].Columns.Exists(OptionColumnKey)) return; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns.Insert(_ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[_ugvhConfig.ColumnNameFirstName].Index + 1, OptionColumnKey); _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].ButtonDisplayStyle = ButtonDisplayStyle.Always; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].Width = 24; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].MinWidth = 24; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].MaxWidth = 24; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].Header.Caption = ""; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].AllowRowFiltering = DefaultableBoolean.False; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].Header.Appearance.Image = Common.Graphics.Tools.ImageTool.resizeImage(Resources._1280829161_media_repeat, new Size(24, 24)); _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].Header.Appearance.ImageHAlign = HAlign.Center; }
The code above works perfectly with grids that do not have a ColumnLayout.
Due to the fact that we will use this maybe in 3-5 different locations that already have ColumnLayouts I was wondering if modifying the function above to distinguish between grist with or without ColumnLayout would be quite a big task compared to the time it'll take to remove the ColumnLayout from the grids and reposition/reformat the columns using the designer-dialog.
I fear that I'll end up repositioning every ColumnInfo (Origin/Span) after the inserted position...
What do you think would be an appropriate approach?
In the meantime I'll check out the GridBagLayout you have told me about.
Thanks for your fast reply Mike,I kindly appreciate that.
best regardsAndy
it seems that the code was kind of cut of...
protected virtual void AddOptionColumn(){ if (_ugvhConfig.Grid.DisplayLayout.Bands[0].Columns.Exists(OptionColumnKey)) return;
_ugvhConfig.Grid.DisplayLayout.Bands[0].Columns.Insert(_ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[_ugvhConfig.ColumnNameFirstName].Index + 1, OptionColumnKey); _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].ButtonDisplayStyle = ButtonDisplayStyle.Always; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].Width = 24; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].MinWidth = 24; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].MaxWidth = 24; _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].Header.Caption = "";
_ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].AllowRowFiltering = DefaultableBoolean.False;
_ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].Header.Appearance.Image = Common.Graphics.Tools.ImageTool.resizeImage(Resources._1280829161_media_repeat, new Size(24, 24)); _ugvhConfig.Grid.DisplayLayout.Bands[0].Columns[OptionColumnKey].Header.Appearance.ImageHAlign = HAlign.Center;
}
Hi Mike,thanks for pointing out the "how to post code", I somehow lost that ;)
I totally agree with you regarding the question "why we use a ColumnLayout".I can not answer this, because I am just writing the extender for the grid.I talked to the guys who are in charge for the grids itself and it turned out that it was just easier to manipulate the appearance of the grid using the RowLayout-dialog of the WinGridDesigner.
We now decided to turn that off and reformat the related grids using the "User Groups and Levels" dialog of the WinGridDesigner, which turned out to be the fastest solution.
I had to change the process of adding/inserting columns, so I switched over to xxx.DisplayLayout.Bands[0].Columns["xxx"].Header.VisiblePosition for arranging the columns.
Thanks a lot for your help Mike,all the best
Andy
Hi,
If you want to post code on the forum, you can surround it in a code tag.
Anyway, if switching RowLayouts off and then back on works, it's probably resetting the layout. If that's the case, it sounds like you are using a flat layout, anyway. Which begs the question, why are you using a ColumnLayout in the first place? It might be easier for you to simply turn off the RowLayouts and leave it off if it is just causing difficulties and you are not really using the capabilities of it, anyway. :)
...when I add the following line before adding columns it works:
ultraGrid1.DisplayLayout.Bands(0).RowLayoutStyle = RowLayoutStyle.None
ultraGrid1.DisplayLayout.Bands(0).RowLayoutStyle = RowLayoutStyle.ColumnLayout
Does that make sense?Maybe I am totally wrong assuming the RowLayout is responsible...