10-09-2012 11:33 AM
Hi all,
I have a PropertyEditor hosted into a cell in datagridview. My problem was that when cell loses focus, this propertyeditor makes invisible and only is visible when entering in edit mode. I have searched for information and it is a normal behaviour of datagridview when hosting custom controls. So to solve this problem, I overrided the paint method:
protected override void Paint( Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // Call the base class method to paint the default cell appearance. base.Paint( graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); PropertyEditor propertyEditor = (PropertyEditor)this.DataGridView.Rows[rowIndex].Cells[this.ColumnIndex].Value; Bitmap img = new Bitmap(cellBounds.Width, cellBounds.Height); // Resize propertyEditor control to cell bounds propertyEditor.Height = cellBounds.Height; propertyEditor.Width = cellBounds.Width; // Sets the cell's backcolor according to the data grid view's color propertyEditor.BackColor = this.DataGridView.Rows[rowIndex].Cells[this.ColumnIndex].Style.BackColor; // Finally paint the propertyEditor control propertyEditor.DrawToBitmap(img, new Rectangle(0, 0, propertyEditor.Width, propertyEditor.Height)); graphics.DrawImage(img, cellBounds.Location); }
This is working in Windows 7 but not in Windows XP.
Any ideas?
10-12-2012 03:25 AM
Hi NI Engineers,
Is PropertyEditor and Ink control? If so, DrawToBitmap is not supporting it according to microsoft.
According to MSDN, The DrawToBitmap method has the following limitations:
Please, could you confirm me that? Is it the reason because DrawToBitmap is not generating the correct image? I work in a company and we have purchased your Measurement studio software so please, provide help.
Thanks in advance.