DataGrid cell formatting

Using the DataGrid control in VB6, is it possible to change the background color of a particular cell (or another attribute like the fore color, the font, ...)?
LVL 71
Éric MoreauSenior .Net ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

3rsrichardCommented:
I know this is a lazy answer, but the IDE will tell you.
When you type in DataGrid1.
you can search through the autocomplete list and if you can find a step you want
select it then type in . and it will show you the next set of choices.
0
Éric MoreauSenior .Net ConsultantAuthor Commented:
I have already check this!!! If I had found something, I didn't ask for it!

0
3rsrichardCommented:
I did manage to look in the MSDN library and they don't list any properties for cells except Text and
Value.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

RuchiCommented:
You can easily create a floating text box ... This text box will be positioned in the celling using the properties... cellleft, celltop, cellwidth, cellheight. Set Text1.Background to Blue...

This might give you an idea..


    Grid1.Row = Grid1.MouseRow
    Grid1.Col = Grid1.MouseCol
    Text1.Text = ""
    Text1.Visible = False
    Text1.Top = Grid1.Top + Grid1.CellTop
    Text1.Left = Grid1.Left + Grid1.CellLeft
    Text1.Width = Grid1.CellWidth
    Text1.Height = Grid1.CellHeight
    Text1.Text = Grid1.Text
    Text1.Visible = True
    Text1.SetFocus
0
Éric MoreauSenior .Net ConsultantAuthor Commented:
For Ruchi:

I like this idea BUT I use the "DataGrid" control (not the DBGrid or the Grid control). Then I don't have all of these Cell... properties.
0
RuchiCommented:
Oh, you are using the "DataGrid" control. I don't know about its properties. All the best to you.
0
chewhoungCommented:
DBGrid cell does not support colouring.

The MS Flexgrid control can be used to display data similarly to the dbgrid control. You can also set the colours of individual cells in the grid.

The following example shows how you could use this to display alternate lines in a different color.

Private Sub Command2_Click()
    For intRow = 0 To MSFlexGrid1.Rows - 1 Step 2
        MSFlexGrid1.Row = intRow
        For intCol = 0 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = intCol
            MSFlexGrid1.CellBackColor = vbBlue
            MSFlexGrid1.CellForeColor = vbYellow
        Next
    Next
End Sub
 
 

If you don't want to use MSFlexgrid
Here's the link to a few grid control that support cell colouring:

http://download.cnet.com/downloads/1,10150,0-10081-103-0-1-7,00.html?tag=st%2Ecn%2E10081%2Dron%2Esbsr&qt=grid&cn=Development+Tools&ca=10081 
 
 

0
Éric MoreauSenior .Net ConsultantAuthor Commented:
From the beginning I have said that I use the "DataGrid" control. I can't use another grid because the project is too deep to change these components.

It would have been a nice feature but if it is not possible... we'll forget it!
0
amebaCommented:
Maybe you can expand this idea:
------------------------------------------
' UserControl name=ctlMarker, BackStyle=Transparent
' add Line control, name=linBdr, index=0, bordercolor=red
'     copy Line control and paste it 3 times
' add this code
Option Explicit

Private Sub UserControl_Resize()
    On Error Resume Next
    Dim uw As Single, uh As Single
    uw = UserControl.ScaleWidth - 15
    uh = UserControl.Height - 15
    linBdr(0).X1 = 0
    linBdr(0).Y1 = 0
    linBdr(0).X2 = uw
    linBdr(0).Y2 = 0
    linBdr(1).X1 = uw
    linBdr(1).Y1 = 0
    linBdr(1).X2 = uw
    linBdr(1).Y2 = uh
    linBdr(2).X1 = uw + 15
    linBdr(2).Y1 = uh
    linBdr(2).X2 = 0
    linBdr(2).Y2 = uh
    linBdr(3).X1 = 0
    linBdr(3).Y1 = uh
    linBdr(3).X2 = 0
    linBdr(3).Y2 = 0
End Sub
------------------------------------------
' Form
' add datagrid and usercontrol (ctlMarker1)
Option Explicit

Private Sub Form_Load()
    HiLiteCell 0, 1
End Sub

Private Sub HiLiteCell(row, col)
    Dim markerLeft, markerTop, markerWidth, markerHeight
    On Error Resume Next
    With DataGrid1
        markerLeft = .Left + .Columns(col).Left + 15
        markerTop = .Top + .RowTop(row) + 15
        markerWidth = .Columns(col).Width - 15
        markerHeight = .RowHeight
    End With
    ' highlight singe cell
    ctlMarker1.Move markerLeft, markerTop, markerWidth, markerHeight
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amebaCommented:
It won't change font, but it will make cell looks different.
To expand the ide, you'll need to add more line controls dinamically...
0
Éric MoreauSenior .Net ConsultantAuthor Commented:
I have just tried it.

I will not use it in my current project (I would have prefer to change backcolor or font) but since you're the only one giving an answer using the "DataControl", I give you the points.
0
amebaCommented:
Tnx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.