Datagrid Readonly Background Color Override?

J

John Smith

Hi All;

I am using the HeaderAndDataAlignColumn class from Ken Tucker. I have
customized it for a wider row. I reposition the DrawString method so the
text is centered vertically in the row.

My problem now is that on ReadOnly cells the shaded background is not at the
top of the cell. I adjust the rectangle Height so that the shading does not
drop into the next row.

Is there an override that I can write to reposition the shaded background?

Thanks.
 
K

Ken Tucker [MVP]

Hi,

In the paint procedure I use the brushes sent it to draw. You can
replace the foreBrush and backBrush with what ever you want to customize its
look. Have fun with it.

Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics,
ByVal bounds As System.Drawing.Rectangle, ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush,
ByVal alignToRight As Boolean)

'clear the cell

g.FillRectangle(backBrush, bounds) ' Could try g.FillRectangle(Brushes.Gray,
bounds)

'draw the value

Dim s As String = Me.GetColumnValueAtRow([source], rowNum).ToString()

Dim r As Rectangle = bounds

r.Inflate(0, -1)

g.DrawString(s, MyBase.TextBox.Font, foreBrush, RectangleF.op_Implicit(r), _

mDrawTxt)

End Sub


Here is a link to some more examples of column styles.
www.onteorasoftware.com/downloads/coloredcolumns.zip


Ken
------------------------
Hi All;

I am using the HeaderAndDataAlignColumn class from Ken Tucker. I have
customized it for a wider row. I reposition the DrawString method so the
text is centered vertically in the row.

My problem now is that on ReadOnly cells the shaded background is not at the
top of the cell. I adjust the rectangle Height so that the shading does not
drop into the next row.

Is there an override that I can write to reposition the shaded background?

Thanks.
 
J

John Smith

Thanks Ken...but...

what I really need is to change the background color and the rectangle
bounds when the cell has focus.
 
J

John Smith

Well...um...maybe I am calling what happens the wrong term.

This is how the cell is set to ReadOnly.

Me.IndividPayDataGridDue.ReadOnly = True


Once I populate the DataGrid with data. You can click on the cell. The text
background becomes blue and the unused portion of the cell becomes shaded.
The text in the cell cannot be changed.

Is this getting Focus, becoming Active or something else? Are both terms
relatively the same?

Anyway, I fix the problem by reducing the bounds.Height in the Edit
Override. Now the only shaded part is the unused portion of the TextBox and
not the entire cell.

Thanks for all your help!!!
I really appreciate it!!




Ken Tucker said:
Hi,

I am not sure how a cell can get focus if it is readonly.

Ken
---------------------------
Thanks Ken...but...

what I really need is to change the background color and the rectangle
bounds when the cell has focus.


Ken Tucker said:
Hi,

In the paint procedure I use the brushes sent it to draw. You can
replace the foreBrush and backBrush with what ever you want to customize its
look. Have fun with it.

Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics,
ByVal bounds As System.Drawing.Rectangle, ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush,
ByVal alignToRight As Boolean)

'clear the cell

g.FillRectangle(backBrush, bounds) ' Could try g.FillRectangle(Brushes.Gray,
bounds)

'draw the value

Dim s As String = Me.GetColumnValueAtRow([source], rowNum).ToString()

Dim r As Rectangle = bounds

r.Inflate(0, -1)

g.DrawString(s, MyBase.TextBox.Font, foreBrush,
RectangleF.op_Implicit(r),
_

mDrawTxt)

End Sub


Here is a link to some more examples of column styles.
www.onteorasoftware.com/downloads/coloredcolumns.zip


Ken
------------------------
Hi All;

I am using the HeaderAndDataAlignColumn class from Ken Tucker. I have
customized it for a wider row. I reposition the DrawString method so the
text is centered vertically in the row.

My problem now is that on ReadOnly cells the shaded background is not at the
top of the cell. I adjust the rectangle Height so that the shading does not
drop into the next row.

Is there an override that I can write to reposition the shaded background?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top