Hi,
In my UltraGrid ther's a count field (datasource of grid is dataview = SQL statement).
I've set the ColumnStyle to button
and the ButtonAppearStyle to Always.
Now when the field = 0 I don't want any button and no image.
When its higher then 0 I would like a button with an image and the text that is the number counted.
In this example the 0 should appear as any other field. (eg 'BE', '10000'...)
Also how can I set the image & text relationship? I'd like the image to be centered as the text.
Thank you for your time!
I recommend using the InitializeRow event. You can examine the value of the Instructions cell. If it is 0, you can set the Hidden property on the cell to hide the cell. Or, you could set the Style of the cell to something other that button - depending on what you want to display there.
For the image, centering the image is very easy. There are properties on the Appearance object for ImageHAlign and ImageVAlign and Image. But there's no easy way to remove the text from the button.
So if you want a button with no text, what I would do is use the InitializeLayout event of the grid and hide the real Instructions column. Then you add an Unbound column to the grid in it's place. Then you can based the Style and Appearance of the cells in the unbound button column on the hidden value of the real, bound column and it won't show any text, since the unbound column values will all be null.
There IS a easy way to remove the text from a button:
You could have told me that for hiding the text on the buttons that are not hidden, I could do this:
this.DisplayLayout.Bands[0].Columns["Instructions"].CellButtonAppearance.ForeColor = Color.Transparent;
Since I add every column manually from a special table in my database that also stores the width, visibleposition, hidden or not... This table is filled based on a script that imports columns as fields from another table, selected on the FormLoad event and updated on the FormClosed event of my ancestor form. With the form id and the userid for each set.
Adding an unbound column caused me a lot of trouble to do just that.
Now everyone knows and can use this :)
The hidden property on the cells where the value = 0 in the InitializeRow event works like a charm!
Thank you for the complete and clear answer.
I've managed to add an unbound column (Column Key "I") with buttons where my hidden-column(Column Key = "Instructions")-cells-values were higher then 0 and display nothing (hide cell) when the values were = 0.
Only thing now is that in my ColumnChooser the both columns (I and Instructions) show up.
This I cannot allow, specially since I have a mechanism to store, for each user on each form, the ColumnsSettings (Visible, width, VisiblePosition..) The user must be able to hide or make visible/change visible position the "I" Column and never to display the "Instructions" column.
How can I make "Instructions" Column disapear from the ColumnChooser?