Let's say I have to display green button icon for column value "1", yellow for column value "2" and red for "3" . I have two requirements
1. Column shows both value and its associated icon. ie. Column value shows "1" <green button icon>, "2" <yellow button icon>, "3" <red button icon>
2. Columns shows only the icon representing the value
Questions:
a. From reading the forum, valuebasedappearance seems to help me achieve both requirements very easily. Is that correct?
b. How would I achieve sorting of the columns in requirement #1 and requirement #2 ?
a) I don't think so. I think you could acheive option 1 here, but not option 2. The ValueBasedAppearance doesn't give you any good way to hide the text of the cell as far as I know.
It sounds to me like you just need a ValueList on the column and you can assign an Appearance to the ValueListItems on the list.The cell will pick up the appearance of the selected item on the ValueList. The ValueList.DisplayStyle allows you to show just a picture with no text.
b) You don't have to do anything. The column will be sorted by it's displayed text.
Hi Mike,
Can you point me towards an example where you put this together?
I want to do something similar, I want to display an image in the cell and no text and don't really understand how to use the valuelist to achieve it? The image would be different depending on the content, for instance if the value pulled back is 1 then display a red arrow image, 2 display a orange arrow etc...
Any pointers would be welcome.
Cheers,John
Here's some sample code. There's really not much to it.
{ UltraGridLayout layout = e.Layout; UltraGridBand rootBand = layout.Bands[0]; UltraGridOverride ov = layout.Override; // Create a ValueList ValueList vl = layout.ValueLists.Add(); // Set it's DisplayStyle to Pictures-only. vl.DisplayStyle = ValueListDisplayStyle.Picture; // Add some items and assign an image to each item. ValueListItem item = vl.ValueListItems.Add(1); item.Appearance.Image = DummyDataCreator.GetTextBitmap("1"); item = vl.ValueListItems.Add(2); item.Appearance.Image = DummyDataCreator.GetTextBitmap("2"); item = vl.ValueListItems.Add(3); item.Appearance.Image = DummyDataCreator.GetTextBitmap("3"); // Assign the ValueList to the column rootBand.Columns["Int32 1"].ValueList = vl; }
Thanks Mike, that helpded me get started and was a good example.
I don't know if I'm doing something wrong but the images I'm loading 32bit, 16x16 are all getting distorted in the grid and look terrible. I have uploaded a screen print including the images I have in windows explorer and the same images as they are displayed in the grid.
The grid images are showing blue as the shadow instead of a light grey, also they look stretched and jagged edges. I'm loading them from an imagelist set to 16x16 and 32bit.
Any ideas what is going wrong?
It might be the ImageList corrupting the images. Make sure you set the size and color depth on the ImageList before you add any images to it. Otherwise, any images you add to the ImageList will be coerced into the default settings for the ImageList.
Also, if your images have an alpha channel, then they might not work in DotNet. Check out this link:
822488 - BUG The Icon That Is Displayed on the Control Loses the Alpha Channel When You Set the Image Property of a Microsoft Windows Form Control to a 32-Bit Alpha-Blended Icon
Hi John, did you find out the reason for the distortion? How did you resolve it? Please post some code if possible.
Thanks!
Hey vrn,
I took Mikes advise and did some testing around the imagelist corruting the images. It appears when the bitdepth is changed from 8 to 32 it has buggered the image. I deleted the images and added them back into the imagelist already set to 32 bit depth first.
Seems to have sorted it out.