in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

DrawCell

Last post 05-06-2008 5:16 PM by DoctorD. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-01-2008 9:42 PM

    DrawCell

     I have a problem with drawinjg graphics from OwnerDrawCell event.

    Everything seems quite simple, however...

     Most of cells have black background. For one cell I draw a red color rectangle (not using a backcolor because ideally this rectangle should occupy just a half of the cell):

     

                    If eventArgs.Col = 4 And eventArgs.Row = 1 Then
                        g.FillRectangle(Brushes.Red, eventArgs.Bounds)
                        eventArgs.DrawCell()
                        Debug.WriteLine("special") ' just a test code to see the code executed
                    End If

     

    However when I start the form the cell is not painted to red color. When I scroll the through columns the rectangle appears (not instantly). And even in this case something is going wrong as red rectangle can be smaller in width then the cell.

    Another (but I believe related) problem is that when scrolling horisontally first column (fixed one) can be partially re-painted with this red color (or any other color we use) .

     

    This code was working with old VS flexgrid and converted Ax flexgrid.

     

     

    Filed under:
  • 05-02-2008 1:26 AM In reply to

    Re: DrawCell

     This is FlexGridClassic

  • 05-05-2008 4:51 PM In reply to

    Re: DrawCell

     OK, I solved the problem myself. It might be interesting for somebody.

     The problem was as follows.

    I was using graphics object I acquired from the grid itself.

            Dim g As Graphics
            g = grdGraph.CreateGraphics

    This approach was used in the old VS flexgrid and worked fine in activeX VSFlexGrid. In C1 flexGridClassic this does not work well. Graphics object to draw cell should be acquired from OwnerDrawCellEventArgs object:L

    eventArgs.Graphics.FillRectangle(Brushes.Red, rc1.Left, rc1.Top, _
        rc1.Right - rc1.Left, rc1.Bottom - rc1.Top)
     

  • 05-06-2008 3:04 AM In reply to

    Re: DrawCell

    Hi,

    the call to "eventArgs.DrawCell" draws the whole cell, with it's background,
    which might overwrite your own rectangle. I would suggest you either make the
    call to "DrawCell" before drawing your own background, or you set the
    "DrawCellFlags" so that all parts without the background are drawn.

    By the way: you might also modify the cell styles "BackColor" property, so you
    would not need any OwnerDrawn grids. CellStyles are a new feature in the .NET
    grid. It is a bit of hard work to get them sorted out, but they are a mighty tool.

    I hope this helps.


    Wolfgang
  • 05-06-2008 5:16 PM In reply to

    Re: DrawCell

     Thanks, Wolfgang,

     I already solved the problem. Howevery what you say is quite useful. I'm in a process of "comprehencing" of CellStyles :)
     

Page 1 of 1 (5 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.