1

I'm using the CustomDrawCellForeground pattern to draw an image in a cell of an iGrid.NET component.

I think in the iGrid ActiveX component, there was a DrawCell() sub that I could call, but in the .NET component (https://10tec.com/winforms-grid/) I just don't find it anymore.

Grid.Refresh would be an overkill. It must be possible to redraw a single cell.

Could anybody please tell me how to force a cell to redraw it's foreground?

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • If it doesn't have an invalidation method for the cell, as an idea, maybe you can try [`Invalidate(Rectangle)`](https://msdn.microsoft.com/en-us/library/8dtk06x2.aspx). (Just sharing an idea, I didn't tried it myself). – Reza Aghaei Aug 13 '18 at 15:56
  • I tried it. It works. – Reza Aghaei Aug 13 '18 at 16:37

1 Answers1

1

You can use Invalidate(Rectangle) method of the control to invalidate the specified rectangle of the graphics object. For example:

iGrid1.Invalidate(iGrid1.Cols[0].Cells[1].Bounds);

Note: The cells which you want to support custom draw for their foreground, should have iGCustomDrawFlags.Foreground flag for their CustomDrawFlags properties and also the CustomDrawCellForeground event should be handled and contain custom paint logic. You can find more about the control in iGrid.NET manual.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • Thank you very much! I'm a bit surprised about this, I expected a dedicated method for a cell, but obviously there isn't one anymore. Perhaps the author thought that Invalidate is more modern approach to handle this. – tmighty Aug 13 '18 at 20:31
  • This answer is wrong. Your code does not only invalidate a single cell as asked in the question. It works, but it invalidates all cells. Put a Debug.Write((String)i_Cell.Value); into your Custom Draw handler and you will see that the grid redraws all cells. – Elmue Mar 02 '21 at 16:28