473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Modify background of datagrid cell.

Hello

I am trying to change the backgroup color of windows form
datagrid. I found a sample class at the following URL
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnwinforms/html/wnf_CustDataGrid.asp
I get a compilation error sub 'Paint' cannot be
declared 'Overrides' because it does not override a sub
in a base class.
<code>
Public Class FormattableTextBoxColumn
Inherits DataGridTextBoxColumn

Public Event SetCellFormat As FormatCellEventHandler

Protected Overloads Overrides Sub Paint()

End Sub 'Paint
End Class
</code>

Does anyone know how to correct the compilation error or
has another class that does the same? Thanks
Kind Regards
Jorge Cavalheiro

Nov 21 '05 #1
3 1844
Jorge,

I do not know if you want to change the cell or the complete background, I
sand today an almost the same sample I once made to Woody, I changed it a
little, have a look at it, probably it is not what you need, however maybe
it is.

\\\
Private WithEvents dtbCol1 As DataGridTextBox
Private ToolTip1 As New ToolTip
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Dim dt As New DataTable("test")
ds.Tables.Add(dt)
dt.Columns.Add("1")
For i As Integer = 0 To 10
Dim dr As DataRow = dt.NewRow
dr(0) = i
dt.Rows.Add(dr)
Next
DataGrid1.ReadOnly = True
Dim ts As New DataGridTableStyle
ts.MappingName = ds.Tables(0).TableName
Dim column As New DataGridTextBoxColumn
ts.GridColumnStyles.Add(column)
DataGrid1.TableStyles.Add(ts)
column = DirectCast(ts.GridColumnStyles(0), DataGridTextBoxColumn)
dtbCol1 = DirectCast(column.TextBox, DataGridTextBox)
column.MappingName = ds.Tables(0).Columns(0).ColumnName
column.HeaderText = "Woody"
column.Width = 30
Dim dv As New DataView(ds.Tables(0))
dv.AllowNew = False
DataGrid1.DataSource = dv
End Sub
Private Sub dtbCol1_ToolTip(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles dtbCol1.MouseEnter
DirectCast(sender, DataGridTextBox).BackColor = Color.Red
End Sub
///
Nov 21 '05 #2
If you take a look in the Object Browser, you will find the
DataGridTextBoxColumn under the System.Windows. Forms heirarchy.

When you find the class, you will notice that it has three Paint methods.
All three Paint methods are Protected Overrides which means that they are
overriding from another superclass.

Each of these methods are overloaded in the DataGridTextBoxColumn Class.
However, they are not marked as Overridable which means you must implement
one of them as is. You are not providing any parameters to you call for
Paint in this sample code.

Take a look at the method signatures to see what is required for each
method.

--
Gerry O'Brien [MVP]
Visual Basic .NET(VB.NET)


"Jorge" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Hello

I am trying to change the backgroup color of windows form
datagrid. I found a sample class at the following URL
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnwinforms/html/wnf_CustDataGrid.asp
I get a compilation error sub 'Paint' cannot be
declared 'Overrides' because it does not override a sub
in a base class.
<code>
Public Class FormattableTextBoxColumn
Inherits DataGridTextBoxColumn

Public Event SetCellFormat As FormatCellEventHandler

Protected Overloads Overrides Sub Paint()

End Sub 'Paint
End Class
</code>

Does anyone know how to correct the compilation error or
has another class that does the same? Thanks
Kind Regards
Jorge Cavalheiro

Nov 21 '05 #3
Thanks Gerry and Cor

-----Original Message-----
Hello

I am trying to change the backgroup color of windows formdatagrid. I found a sample class at the following URL
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnwinforms/html/wnf_CustDataGrid.asp
I get a compilation error sub 'Paint' cannot be
declared 'Overrides' because it does not override a sub
in a base class.
<code>
Public Class FormattableTextBoxColumn
Inherits DataGridTextBoxColumn

Public Event SetCellFormat As FormatCellEventHandler

Protected Overloads Overrides Sub Paint()

End Sub 'Paint
End Class
</code>

Does anyone know how to correct the compilation error or
has another class that does the same? Thanks
Kind Regards
Jorge Cavalheiro

.

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gil | last post by:
Hello, I use VB.NET and have a series of linkbuttons that are inside individual <td>s. Like this: <td background="image.gif"><asp:linkbutton id="myID" runat="server"/></td> I would like...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
5
by: proximus | last post by:
Hi, I am trying to change the background of table TD's. The problem is that I have no access to the HTML code. SO I am trying to alter this using Javascript/DOM in an external .js file. I...
6
by: Barney Nicholls | last post by:
I have a datagrid and want to change the background color of the end column to denote that it is the only column that is not read only. I still want this column to be editable. I've found...
4
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to...
7
by: PJ | last post by:
How can you set the background color of individual columns in a datagrid to be different to others? The table styles only allow you to do this at the grid level for all columns.
4
by: tg | last post by:
Visual Studio 2003 My problem is that I am dynamically creating a datagrid on pageload. The datagrid is completely dynamic as it is based on the number of columns returned from a recordset. The...
4
by: John Smith | last post by:
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. ...
0
by: Serdge Kooleman | last post by:
Winform (DataGrid) when i'm editing the text in the curent cell, i need to change color/font/background in it. thank you
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.