Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2006, 11:04 AM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default editing datagrid and changing cell color upon edit

I am using multiple datagrids in the same form and would like any cell that is editable to change colors upon edit. I have found some code using a ColoredTextBoxColumn that inherits DataGridTextBoxColumn. This will change cell colors when a cell doesn't meet the cutoff value. I need it to change colors when edited. Here is the code that i have came up with so far.


Public Class ColoredTextBoxColumn
        Inherits DataGridTextBoxColumn

        Private m_Cutoff As Single = 0
        Public Sub New(ByVal cutoff As Single)
            m_Cutoff = cutoff
        End Sub

        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 foreBrush As Brush, ByVal backBrush As Brush, ByVal alignToRight As Boolean)
            'get the cell's value
            Dim cell_object As Object
            Dim checkCol, checkRow As Object
            Dim curcell As New DataGridCell
            Dim j, k As Integer
            Dim iselected As String
            Dim ItemsInfo As DataTable

            Dim itm2 As cDieType
            Dim items2 As Collection
            Dim curItem As Object

            cell_object = Me.GetColumnValueAtRow(source, rowNum)

            'if the value is numeric, get its value
            Dim cell_number As Double '= m_Cutoff - 1
            If IsNumeric(cell_object) Then
                cell_number = CType(cell_object, Double)
            End If

            ItemsInfo = Me.DataGridTableStyle.DataGrid.DataSource()

            For k = 0 To ItemsInfo.Rows.Count - 1
                If iselected = Me.DataGridTableStyle.DataGrid.Item(j, 0) Then
                    j = j
                    Exit For
                Else
                    j = j + 1
                End If
            Next
            curcell.RowNumber = j
            curcell.ColumnNumber = 0
            'Me.DataGridTableStyle.DataGrid.CurrentCell = curcell
            'Me.DataGridTableStyle.DataGrid.Select(j)

            'pick appropriate colors
            If (cell_number <> m_Cutoff) Then 'm_Cutoff
                backBrush = Brushes.Pink
                foreBrush = Brushes.Red
            Else
                backBrush = Brushes.White
                foreBrush = Brushes.Black
            End If

            'Draw the cell
            MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)

        End Sub
    End Class





Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing color of page-numbers in DataGrid anup_daware ASP.NET 1.0 and 1.1 Basics 2 October 18th, 2007 07:04 AM
Cell/Font Color in DataGrid. su C# 1 December 3rd, 2006 04:58 AM
back color of cell of datagrid [email protected] VB.NET 1 November 18th, 2006 03:28 AM
changing datagrid row color msrnivas Classic ASP Components 4 August 5th, 2004 10:58 PM
paint color cell in datagrid(c#) kobystud C# 0 August 1st, 2004 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.