Hello, I have a problem and I hope you can help me
I have in the grid a columm “ArtNr”. In the column is a number.
Now I must read the number and replace the number with a icon.
Example:
Is the column “ArtNr” = 2 then load icon (Me.ImageList2.Images(1))
Then you for your help
Frank
Hi Frank,
Before I can point you in the right direction, I need to know a couple of things.
1) Can the user edit this field? Do you want them to be able to drop down a list and pick a new value/icon?
2) Do you want to display both the number and the icon? Or just the icon?
3) How many possible values are there for this field? Is it a limited number like 1 to 5? Or can it be any number?
Hi Mike,
thank you for your answer.
1) no the user can’t edit the field
2) Just the icon
3) 1-8
I've solved the problem as follows:
Private Sub UltraGrid4_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles UltraGrid4.InitializeRow
If e.Row.Cells("ArtNr").Value.ToString = "1" Then
e.Row.Cells("ArtNr").Appearance.ImageBackground = Me.ImageList2.Images(0)
ElseIf e.Row.Cells("ArtNr").Value.ToString = "2" Then
e.Row.Cells("ArtNr").Appearance.ImageBackground = Me.ImageList2.Images(1)
ElseIf e.Row.Cells("ArtNr").Value.ToString = "3" Then
e.Row.Cells("ArtNr").Appearance.ImageBackground = Me.ImageList2.Images(2)
ElseIf e.Row.Cells("ArtNr").Value.ToString = "4" Then
e.Row.Cells("ArtNr").Appearance.ImageBackground = Me.ImageList2.Images(3)
ElseIf e.Row.Cells("ArtNr").Value.ToString = "5" Then
e.Row.Cells("ArtNr").Appearance.ImageBackground = Me.ImageList2.Images(4)
ElseIf e.Row.Cells("ArtNr").Value.ToString = "6" Then
e.Row.Cells("ArtNr").Appearance.ImageBackground = Me.ImageList2.Images(5)
ElseIf e.Row.Cells("ArtNr").Value.ToString = "7" Then
e.Row.Cells("ArtNr").Appearance.ImageBackground = Me.ImageList2.Images(6)
ElseIf e.Row.Cells("ArtNr").Value.ToString = "8" Then
e.Row.Cells("ArtNr").Appearance.ImageBackground = Me.ImageList2.Images(7)
End If
End Sub
Is that correct?
Thank you
thank you very much for your help.
frank
The code you have here is a bit inefficient. I would probably get the cell's value once using e.Row.GetCellValue and store it in a variable instead of getting and re-getting the cells multiple times.
You are also creating a new Appearance object for each cell. It would be more efficient to create 8 Appearance objects and re-use them.
There's more information about making your code more efficient here: WinGrid Performance Guide
But the basic approach you have here is fine if it works for you. The text will still show on top of the ImageBackground, though, and you seem to be saying you don't want that.
If you don't want the text to show, then there are a couple of approaches you could take.
One would be to hide the real column and add an unbound column to your grid whose DataType is Bitmap. Then you could simply set the Value of the cell in that column to the image you want in InitializeRow, very much like you are doing here.
Another option would be to use a ValueList whose style is set to Picture. You build a ValueList with values from 1 to 8 and set the Appearance.Image on each ValueListItem. The ValueList will automatically show the correct image in the cell.