I have a case where I have a datasource with an ID, a Code and an Image.
I have no problems data binding a tlist of that entity to a grid or an ultracombo to display it.
For this particular requirement, I want to have my usercontrol which uses a picture box and a ultralabel to show as the displaytext of the ultracombo.
So no only with I see the code and the image when i drop down (which I can do now) but whatever I choose, I will be able to see it in the display value area (the not dropped down combo)
Is that something that is doable ?
Thanks in advance
Hi,
Okay... in that case, this is really easy. All you have to do is apply the image to the cell with the DisplayMember and the image of the selected item will show up in the edit portion of the control automatically.
If you image is in a separate column in the dropdown, then what I would do is hide that column:
private void ultraCombo1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { e.Layout.Bands[0].Columns["Image 1"].Hidden = true; }
And then use InitializeRow to show that image in the DisplayMember column:
private void ultraCombo1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { e.Row.Cells["String 1"].Appearance.Image = e.Row.Cells["Image 1"].Value; }
I must be getting closer, but still no dice.
I see the image in the column if i dont hide it
I added the code as you told me to.. I get no error message, but only the code is shown.
Do I have to cast the Value to something else . my datasource returns it as a {System.Array}
I tried to replace the image i am adding in the initializerow... using a ressource from my project. when i do that and i drop down the ultracombo object, i see the image and the code in the same column.
However, I only see the code in the DisplayMember.
Here is my code
In the Sub New()
Dim bs As New BindingSource bs.DataSource = ListCouleurs BindingNavigator1.BindingSource = bs Me.UltraCombo1.ValueMember = CouleursColumn.Id.ToString Me.UltraCombo1.DisplayMember = CouleursColumn.Code.ToString Me.UltraCombo1.DataSource = bs
In the InitializeLayout
e.Layout.Bands(0).Columns(CouleursColumn.Image.ToString).Hidden = True
In the InitializeRow
e.Row.Cells(CouleursColumn.Code.ToString).Appearance.Image = e.Row.Cells(CouleursColumn.Image.ToString).Value
Fred Morin said:Do I have to cast the Value to something else . my datasource returns it as a {System.Array}
You mean your image column is an array? Okay, so your images are stored in a Byte array. That makes this a little trickier. I assume, in that case, that you also don't see the image in the DisplayMember column of the dropdown, either.
In that case, you have to convert that byte array into a System.Drawing.Image before you assign it to the Appearance. The grid does this for you in the column containing the byte array, but the Value of the cell will still return the Byte array data and not the image.
There's no really easy way to do this, and I don't have a sample with byte array data to test with, but I think what you can do is something like this:
private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { object imageCellValue = e.Row.Cells["Image column"].Value; Image image = GetImageRendererImage(e.Row, e.Row.Band.Columns["Image column"], imageCellValue); e.Row.Cells["DisplayMember Column"].Appearance.Image = image; } internal static System.Drawing.Image GetImageRendererImage(UltraGridRow gridRow, UltraGridColumn gridColumn, object cellValue) { EmbeddableImageRenderer embeddableImageRenderer = gridRow.GetEditorResolved(gridColumn) as EmbeddableImageRenderer; if (embeddableImageRenderer == null) { Debug.Fail("GetImageRendererImage is only valid for cells that are using an EmbeddableImageRenderer"); return null; } EmbeddableEditorOwnerBase editorOwner; object ownerContext; GetOwnerInfo(gridRow, gridColumn, out editorOwner, out ownerContext); Stream imageStream; bool disposeImage; return embeddableImageRenderer.GetImage(cellValue, editorOwner, ownerContext, out imageStream, out disposeImage); } internal static void GetOwnerInfo(UltraGridRow gridRow, UltraGridColumn gridColumn, out EmbeddableEditorOwnerBase editorOwner, out object ownerContext) { IGridDesignInfo iGridDesignInfo = gridRow.Band.Layout.Grid as IGridDesignInfo; editorOwner = iGridDesignInfo.GetEditorOwner(gridRow, gridColumn); ownerContext = gridRow; }
Got my hands on a 9.2.20092.2058 version and sure enough it worked..
thanks for your help
Fred
Me.UltraCombo1.DisplayMember = CouleursColumn.Code.ToString
Most Columns are hidden
For Each c As UltraGridColumn In e.Layout.Bands(0).Columns c.Hidden = True Next e.Layout.Bands(0).Columns(CouleursColumn.Image.ToString).Style = ColumnStyle.Image e.Layout.Bands(0).Columns(CouleursColumn.Code.ToString).Hidden = False
Using version 8.2.20082.1000
Would like to get my boss to pay for an upgrade soon.. but for now no go
Yeah I use UltraCombo1.InitializeRow
Hm.
The Code column is your DisplayMember column, right? Do you have any hidden columns here?
What version of the controls are you using? Maybe this is a bug in an old version.
What event are you using to apply the Image? IniitalizeRow?
OK I ported your code to VB.NET and now I get an image for the datarow which have an image
however even with the bitmap,
If Image Is Nothing Then e.Row.Cells(CouleursColumn.Code.ToString).Appearance.Image = My.Resources.Notepad_48 Else e.Row.Cells(CouleursColumn.Code.ToString).Appearance.Image = Image End If
both those possibilities do not change
This is what i get now....