in

datagridtextcolumn focus change color

i have a datagridtextcolumn in my datagrid
this is the function for creating new textboxcolumn but i want to change the background color of the datagridtextcolumn on focus
 Private Function CreateTextColumn(ByVal sColumnName As String, ByVal sHeaderText As String, ByVal iColWidth As Integer, ByVal bRightAlign As Boolean, ByVal textread As Boolean) As DataGridColumnStyle
        ' Text box column style
        Dim textCol As DataGridTextBoxColumn = New DataGridTextBoxColumn
        AddHandler textCol.TextBox.KeyDown, AddressOf CellKeyPress
        ' Set column mappings and Header text
        textCol.MappingName = sColumnName
        textCol.HeaderText = sHeaderText
        'Set column width
        textCol.Width = iColWidth
        textCol.ReadOnly = textread
        textCol.TextBox.Multiline = True
        textCol.TextBox.AcceptsReturn = True
        textCol.TextBox.WordWrap = True
        textCol.TextBox.MaxLength = 50

        'Dim tbc As DataGridTextBoxColumn = New DataGridTextBoxColumn

        If bRightAlign Then
            textCol.Alignment = HorizontalAlignment.Right
        End If

        Return textCol
        End Function
Movie Stars

Solution: datagridtextcolumn focus change color

Yeah, my brain read "DataGridViewTextBoxColumn" instead of "DataGridTextBoxColumn"

You need to implement a custom class to change the background color for a DataGrid cell:

How do I color a individual cell depending upon its value or some external method
http://www.syncfusion.com/faq/windowsforms/search/745.aspx

Bob
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
Public Class DataGridColoredTextBoxColumn 
 
     Inherits DataGridTextBoxColumn 
 
 
 
     Public Sub New() 
 
     End Sub 
 
 
 
     Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean) 
 
 
 
     ' the idea is to conditionally set the foreBrush and/or backbrush 
 
     ' depending upon some crireria on the cell value 
 
     ' Here, we color anything that begins with a letter higher than 'F' 
 
     Try 
 
          Dim o As Object 
 
          o = Me.GetColumnValueAtRow(source, rowNum) 
 
          If (Not (o) Is Nothing) Then 
 
               Dim c As Char 
 
               c = CType(o, String).Substring(0, 1) 
 
               If (c > "F") Then 
 
                     ' could be as simple as 
 
                    ' backBrush = new SolidBrush(Color.Pink); 
 
                    ' or something fancier... 
 
                    backBrush = New LinearGradientBrush(bounds, Color.FromArgb(255, 200, 200), Color.FromArgb(128, 20, 20), LinearGradientMode.BackwardDiagonal) 
 
                    foreBrush = New SolidBrush(Color.White) 
 
               End If 
 
          End If 
 
          Catch ex As Exception 
 
               ' empty catch 
 
          Finally 
 
               ' make sure the base class gets called to do the drawing with 
 
                ' the possibly changed brushes 
 
               MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight) 
 
          End Try 
  
     End Sub 
 
End Class