I'm loocking for the best control for a pick list of items. One item has two attributes (item-code, item-text). I can do it with a multi column listbox of the standard windows forms control.
To have a nicer look (headers, images), I tried the UltraListView control. If users resizes the control the columns should be rearranged to avoid scrollbars as possible (like multicolumn listbox). The ListView control shows this behavior in view type "list", but not in "detailed".
How setup the ListView control for my needs? If not possible, any suggestions for another control?
Thanks for your help.
Regards. Markus
Hello ,
When UltraListView is in Details view, actually it display a grid with at least one Main column (unique for the grid) and other columns, which could be used to represent a different information, depends on the custom customer needs. That is why when UltraListView is in Details view , the component shouldn’t rearrange its items in more than one main columns. As you said UltraListView cover your requirements when it is in List view mode, why you want then to use it in Details mode, maybe I am missing something from your scenario?
Please let me know if you have any further questions.
Hello,
I have to display at least two properties of my items: one column for the item-code, one column for the item-text. Thats the reason I'm using Details mode.
For that, I'm looking what solutions I have to solve these requirements. One solution is the Windows Forms listbox in multi column mode. The ListView Control can have headers and images and looks nicer. This is why I'm try to configure the ListView control to achieve the same behaviour.
If ListView Details mode can not be configured as needed, you mybe has any other suggestions? There are lots of controls with lots of capabilities and, maybe, I'm missing something.
Hello Hristo,
There is still one problem in your formatting example. You format the item text as follows:
string.Format("{0,15} {1,30}",string.Format("Item{0,3}",i),string.Format("Info for Item{0,3}",i)),null );
If the first "column" of the text has different length, the second "column" is not aligned nice. In your example this is when Item-no needs 2 digits (Item 9 -> Item 10).
I like to align the parts left. Is there a way to format the first part {0,-15} to fixed width, to start the second part always aligned at the same position?
Thanks in advance for your suggestions.
Markus
The first parameter in curly brasses “{}”, indicate the index of the parameter from the object[], which will be displayed, the second parameter determines minimum number of characters in the string representation of the object to be formatted. For more information please review the next link:
http://msdn.microsoft.com/en-us/library/1ksz8yb7.aspx
So I think that you should be sure that the text which will be displayed in the “column” is shorter that the minimum number of characters in the string representation of the object to be formatted.
Please let me know if you have any further questions, related to Infragistics.
I know about the parameters. That was not my question. The point is that not any combination of different characters up to the length specified in the second parameters have the same width (in pixels !!!). Therefore the second part of the string starts not at the same position in every ListViewItem (see attached pic to see what I mean). I hope you understand now.
I have tried to fill up with blanks, but the width varies still a little bit.
Is there a way to use tabstop positions and start the second part at this (fixed) position? Why you don't have a UltraListBox control?!
Regards
The behavior which you are facing is caused by the fact that the font which you are using has a different with for the different characters. You could create a class, which will represent your two-column item and also to make own implementation of CreationFilter interface, in order to display a different text editor for each “column”. I have implemented my idea in a small sample. Please run the sample and move slider of “First Column Width %” track bar, in order to adjust the width of the first column, then move slider of “Define UltraListView Column Width” track bar, in order to apply the changes.
thank you for the sample. Interesting idea. I have looked at it now. It seems that the problem still resides (see printscreen of your sample). In the picture you see that the second "column" is not at the same position for Item 9 and Item 10.
I have not figured all details of your solution. You said it's just a idea. Maybe I can play around a little bit. If it is possible to define two controls and their sizes, I guess it must be possible to define it the same size for all items. I don't know?
Do you have a suggestion to improve the sample?
Hello again,
I can not setup the editor sizes and column width properly. In your sample there are combinations of first column width % and UltraListView column width everything looks fine. But if you increase the values the item text gets truncated by the selection rectangel.
I could not figure out how are the selection rectangle is calculated or how I can configure this?
I calculate the maxWidth of firstColumn and secondColumn using draw utility and use this values to specify c1Size and c2Size in the creation filter:
Size c1Size = new Size( this.maxFirstColumnWidth, editor.Rect.Height );Size c2Size = new Size( editor.Parent.Parent.Rect.Width - c1Size.Width, editor.Rect.Height );
Once I set the UltraListViev.ViewSettingsList.ColumnWidth = maxFirstColumnWidth + maxSecColumnWidth).
But this does not help. Item Text is still truncated if selected even if the sizes of the two EditorWithTextDisplayTextUIElement not exceed the parent editor.
Can you give me some more advises?
Thank you
thank you for your solution. Your sample works with correct aligned "columns" but with the selection of a item is something wrong (see attached pic). The second "column" is somewhat truncated. The amount of truncation depends on the width scrollbar settings.
Do you know why this happens?
This little difference caused by the fact that we should get width of the UltraListViewItemEditorAreaUIElement in order to calculate correctly locations and widths of the EditorWithTextDisplayTextUIElement which you are using to display two columns. So you could fix this if you change the code in MyCreation class AfterCreateChildElements method as followed:
EditorWithTextUIElement editor = parent as EditorWithTextUIElement;
if (editor != null && editor.HasChildElements)
{
TwoColumnItemString value = ((Infragistics.Win.UltraWinListView.UltraListViewMainItemTextAreaUIElement)(editor.Parent)).Item.Value as TwoColumnItemString;
if (value != null)
editor.ChildElements.Clear();
EditorWithTextDisplayTextUIElement c1 = new EditorWithTextDisplayTextUIElement(editor, value.FColumn);
EditorWithTextDisplayTextUIElement c2 = new EditorWithTextDisplayTextUIElement(editor, value.SColumn);
Size c1Size = new Size((int)(TwoColumnItemString.FColWidthPercent * editor.Parent.Parent .Rect.Width), editor.Rect.Height);
Size c2Size = new Size(editor.Parent.Parent .Rect.Width - c1Size.Width, editor.Rect.Height);
c1.Rect = new Rectangle(editor.Rect.Location, c1Size );
c2.Rect = new Rectangle(new Point(editor.Rect.Location.X + c1Size .Width,editor.Rect.Location.Y)
, c2Size );
editor.ChildElements.Add(c1);
editor.ChildElements.Add(c2);
}
Please feel free to modify the sample base on your needs.
probably I have found the problem. If I set the width to a fixed size for c1Size it looks nice:
Size c1Size = new Size( 95, editor.Rect.Height );
I can determine the longest text for "column 1" from my domain and measure the string size using draw utility and set the size to this value.
Graphics graphics = DrawUtility.GetCachedGraphics( this.ListView1 );
try {
string refMaxString = new String( 'D', this.maxDomainLen + 1 ) );
this.maxWidth = (int)graphics.MeasureString( refMaxString, this.ListView1.Font ).Width;
finally {
DrawUtility.ReleaseCachedGraphics( graphics );
I will try to use this in my project. Thanks for the idea.