Home Forums WinForms controls Xceed Grid for WinForms Set background image for columnheader from code

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14796 |

    I spent a couple of time to figure out how set a background image to columnheaders, but no success. If I do this from the designer, it works correctly – but if I want to do this in run-time, there’s no success. (In run-time the number of columns are not known)

    foreach (ColumnManagerCell c in ConnectorGrid.columnManagerRowX.Cells) {
    using(Stream stream = (typeof(frmSelect)).Assembly.GetManifestResourceStream( “arNETReport.ColumnHeader Grey.png”))
    c.BackgroundImage = new Bitmap(new Bitmap(stream));
    c.BackgroundImageStyle = ImageStyle.Stretch;
    }

    If I try to change the ForeColor property, it works correctly. But if I try to change the BackColor, or set a background image, simply doesn’t work.

    Also I want to avoid custom painting, if it’s possible. Do you have any idea how to accomplish this?

    Imported from legacy forums. Posted by Szabolcs (had 4715 views)

    User (Old forums)
    Member
    Post count: 23064

    This should work fine, except that there is something a bit awkward in your code. If ConnectorGrid is your GridControl, ConnectorGrid.columnManagerRowX should not compile, since the only way to access the ColumnManagerRow through the GridControl is through the FixedHeaderRows collection, or, of course through the ColumnManagerRow instance itself.

    e.g. :

    //Through the GridControl
    //the index in the FixedHeaderRows will depend on the other rows it may contain, like a GroupByRow
    ( ( ColumnManagerRow ) gridControl1.FixedHeaderRows[ 1 ]).Cells[ 0 ].BackgroundImage = new Bitmap( @”D:\Test.ico” );
    ( ( ColumnManagerRow ) gridControl1.FixedHeaderRows[ 1 ]).Cells[ 0 ].BackgroundImageAlignment = ContentAlignment.MiddleLeft;

    //Through the instance itself
    columnManagerRow1.Cells[ 0 ].BackgroundImage = new Bitmap( @”D:\Test.ico” );
    columnManagerRow1.Cells[ 0 ].BackgroundImageAlignment = ContentAlignment.MiddleLeft;

    What do you mean by “avoid custom painting”?

    Imported from legacy forums. Posted by André (had 297 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello Andre!

    Thank you for the prompt answer! The problem solved – the reason of the problem was that I used an incorrect string format when I tried to call new Bitmap (the image is an embedded image, and I used an incorrect specifier)

    ConnectorGrid is not a gridControl, it is a usercontrol, which holds many other controls – so this works fine.

    Custom painting means something, that Xceed used in the
    CustomUI/CustomColumnManagerCell class – where the CustomColumnManagerRow class is using CustomColumnManagerCell objects to display the column headers.

    The CustomColumnManagerCell class’ PaintBackground method was overriden to give custom look to the column header.

    Imported from legacy forums. Posted by Szabolcs (had 596 views)

    User (Old forums)
    Member
    Post count: 23064

    Interesting. I’m trying to get a column image working for all columns in design mode. All I’m doing is setting the BackgroundImage to an image resource as well as setting it to stretch in the Column Manager. I then have code that binds the data to the grid and NO IMAGE. I can easily set the BackColor in the designer and that is fine. However, I can not get an image to appear. Is there any constraints as to the type or size of the image? I’m using a very small (1k) JPEG that I want to stretch. Basically it is to give the illusion of a Gradient.

    Come to think of it… is there an easier way to do this? I’m trying to come up with a Vista style grid and would love to know the easiest way to do so… I’ve looked into the StyleSheet example but in no way does it go over how to create your own, or best practices…

    Thanks,
    – jv

    Imported from legacy forums. Posted by jvelite (had 515 views)

    User (Old forums)
    Member
    Post count: 23064

    From what you posted <a href=”http://www.xceedsoft.com/Forums/ShowPost.aspx?PostID=5053″>here</a&gt;, you need to do it on the ColumnManagerCell, and not on the row, for it gets painted over by the cell.

    Imported from legacy forums. Posted by André (had 428 views)

    User (Old forums)
    Member
    Post count: 23064

    I’ve made a few posts on this same topic all related to each other. My problem now is I can’t do it using a simple stylesheet class. For now I can only change colors with the stylesheet. Let me know if this bug is fixed please. Oh, and I don’t see where the Grid.FixedColumns…BackColor can be set in a stylesheet (that was another one of my topics).

    Thanks,
    – jv

    Imported from legacy forums. Posted by jvelite (had 805 views)

    User (Old forums)
    Member
    Post count: 23064

    There is no FixedColumnsBackColor property. You need to cycle through each column that is fixed, and change the BackColor for each one. If you permit the user to change which columns are fixed, you need to subscribe to the required events (e.g. FixedChanged on the Column) to toggle the BackColor.

    As for the StyleSheet, it is not a bug, that’s the way it is.

    Imported from legacy forums. Posted by André (had 5570 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.