abraXus
  • abraXus
  • Advanced Member Topic Starter
2022-06-15T08:51:44Z
I am using CustomDrawCellBackground and when the control loses focus, it does not redraw the background like I would expect.
To demonstrate, create a Winform with an iGrid and a text box. Add this code
Run it, click on one of the red cells (it turns blue as it's selected)
Then click on the textbox, and the cell will turn white instead of remaining red or blue.

Is there another way to do this? What am I doing wrong? (see my comments in the code to see the 2 things I have tried so far)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        TextBox1.Text = Now
        IGrid1.Cols.Count = 10
        IGrid1.Rows.Count = 10
        For Each iCell As iGCell In IGrid1.Cells
            iCell.CustomDrawFlags = iGCustomDrawFlags.Background
        Next

        ' this "fixes" it, as the cell then stays blue
        ' but I want it to stay the color is was previously - red, as if nothing is selected
        'IGrid1.SelCellsBackColorNoFocus = IGrid1.SelCellsBackColor
        'IGrid1.SelCellsForeColorNoFocus = IGrid1.SelCellsForeColor

    End Sub

    Private Sub ig_CustomDrawCellBackground(sender As Object, e As iGCustomDrawCellEventArgs) Handles IGrid1.CustomDrawCellBackground
        e.Graphics.FillRectangle(New SolidBrush(Color.Red), e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
    End Sub

    Private Sub IGrid1_LostFocus(sender As Object, e As EventArgs) Handles IGrid1.LostFocus
        ' this fixes it, but then i cant edit the cell
        ' IGrid1.CurCell = Nothing
    End Sub
Igor/10Tec
2022-06-15T14:49:10Z
I've checked this. iGrid works as expected. If iGrid loses the input focus, its current cell is drawn using the special colors set in the SelCellsBackColorNoFocus/SelCellsForeColorNoFocus properties of iGrid. And actually the background color of the selected cell when iGrid is not focused is a light gray, not white.
abraXus
  • abraXus
  • Advanced Member Topic Starter
2022-06-15T19:05:30Z
Since asking the question, I also tried not using the CustomDraw and set it up just using normal background color and it acts exactly the same.

So I guess the only way to get what I want then (in this example) is to hard code the NoFocus color.

IGrid1.SelCellsBackColorNoFocus = Color.Red

And make sure it matches what I have in the CustomDraw routine.
There are probably other drawbacks to this that I will soon discover, but it seems to be the only option based on your answer.

Still open to an alternatives/tricks that you might have.

Igor/10Tec
2022-06-16T06:38:28Z
It's not clear from your very first post what is your goal. If you want to remove the selection color from the current cell when iGrid loses the input focus so that this cell will be highlighted with the background color from the CustomDrawCellBackground event handler, then you can simply set the selection background color when iGrid is not focused to the special 'transparent' value:

IGrid1.SelCellsBackColorNoFocus = Color.Transparent