I am wanting to change my WinGrid cell button appearance depending on a value I have flagged (a boolean flag coming from the stored procedure).
I have been successful in changing the appearance, a little, at least enough to know that it can be changed some. I just want to make the button appearance change more drastic.
In the Win Grid Initialize Row procedure I have the following code...
If e.Row.Cells("Notes_Flag").Value = True Then e.Row.Cells("Notes").ButtonAppearance.ForeColor = Color.Blacke.Row.Cells("Notes").ButtonAppearance.ThemedElementAlpha = Alpha.Transparent e.Row.Cells("Notes").ButtonAppearance.Image = "~/Images/Notes.jpg"Else e.Row.Cells("Notes").ButtonAppearance.ForeColor = Color.Beige End If
e.Row.Cells("Notes").ButtonAppearance.ForeColor = Color.Blacke.Row.Cells("Notes").ButtonAppearance.ThemedElementAlpha = Alpha.Transparent e.Row.Cells("Notes").ButtonAppearance.Image = "~/Images/Notes.jpg"
e.Row.Cells("Notes").ButtonAppearance.ForeColor = Color.Black
e.Row.Cells("Notes").ButtonAppearance.Image = "~/Images/Notes.jpg"
e.Row.Cells("Notes").ButtonAppearance.ForeColor = Color.Beige
End If
So now my button will change to the display text of black, and the button looks like a plain jane Windows button, if the flag = True. If the flag = False, the button will change the text to the color of Beige (not visible) and the button looks like a XP button. So I can tell quickly which records has the Notes_Flag checked and which ones do not.
Now I am wanting to spruce this up.
I would like to do the following...
The button's value is based on an ID, and this ID is needed to be passed to a stored procedure. But I would like to either change the text of the button to read "Notes" (instead of displaying the ID value) OR insert an image (which ever is easier). My code above to insert the image is ignored and I am not certain why.
Is this possible, or must the Button display the value of the cell it is connected to (unbound column)?
Thank you,
T.J.
Hi T.J.,
In order to answer your question, I need to know how you are creating the button in the cell. Are you just setting the Style on the column? If so, what Style are you using? Or are you using an editor to get the button?
On a side note, this code is going to be very inefficient. By doing this, you will create a new Appearance object for every cell. So you are creating a large number of Appearance objects with the same properties. It would be better to use the InitializeLayout event of the grid to add an Appearance to the Appearances collection of the DisplayLayout and then assign that Appearance to the ButtonAppearance of the cell - thus re-using the same appearance.
TBernard said:e.Row.Cells("Notes").ButtonAppearance.ForeColor = Color.Blacke.Row.Cells("Notes").ButtonAppearance.ThemedElementAlpha = Alpha.Transparent e.Row.Cells("Notes").ButtonAppearance.Image = "~/Images/Notes.jpg"
Mike,
Thank you for your help, I greatly appreciate it.
I created the button by going to the WinGrid Designer to add a new Unbound Column. For this column, I set the Key equal to the field in my stored procedure when contained the ID I need to pass to a pop-up form this button will open (Field name "Notes"). I set the Style of the column = "Button". I set the Button Display Style = "Always" and I set the Cell Button Appearance Key property = "Notes" as well.
So this column is simply a button style column (set on the Win Grid Designer) and it contains the data for the [Notes] field in my stored procedure.
Is there a better way to set-up my button column, to allow for the text to read "Notes" instead of the data value in the [Notes] field?
It would be great if the button would display the text "Notes" where my [Notes_Flag] field was True, and the button to be empty when my [Notes_Flag] field is false. The [Notes_Flag] field is a Boolean field in my stored procedure which is also set to an Unbound (and hidden) column on my Win Grid.
Thank you very much for your help.