Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

MSFlexGrid Cell Colors

I am using code similar to that below to change the background color of a row in a data-bound MSFlexGrid. Basically I need to highlight rows where column 10 is a null string. Here's the code:

For iRow = 1 To MSFlexGrid1.Rows - 1
If MSFlexGrid1.TextMatrix(iRow, 10) = "" Then
For iCol = 0 To 10
MSFlexGrid1.Row = iRow
MSFlexGrid1.Col = iCol
MSFlexGrid1.CellBackColor = &HCCCCFF
Next iCol
End If
Next iRow

(There are 11 columns in the FlexGrid)

This works fine but it is really SLOW! It takes a noticeable time to change the colors of about 20 rows on 2.2 GHz CPU. Is there a faster way to do this with an MSFlexGrid or MSHFlexGrid control?

Be gentle with me; this is my first post to this forum



View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
MSFlexgrid And Cell Colors
Does any1 know how to make certain cells in a MSFlexgrid so that it will have different back/fore color?

The cell seems to have the back/foreground color, but I do not
know how to make it so that only specific cell would
have specific color.

Thanks in advance for any inputs.

Msflexgrid Directly Writing On The Cell,resize Cell Auto?

First:***** MSFlexgrid control:when I click the control , I want to access to grid and directly write on selected cell , not to use with inpubox or textbox...etc.How?

Second:*****How can I let the msflexgrid control resize its cell width according to text length?


Altering A MSFlexgrid Cell Without Cell Getting Focus
I am populating a msflexgrid either from a file or by user input.  If the value in any row for column 5 is > 50 and < 200 then the cell backcolor for that cell is red else white.

Doing this is not an issue.  The issue lies in that column 5 for any particular row may not get the focus.  We have locks on certain columns depending on what is entered in earlier columns.

example: If inputing data and col 1 for a particular row is 1 then allow focus to coloumns 2, 3 and 7 of that row etc.

If input data for col 1 is 2 then allow focus to columns 2, 3 and 5

Problem is that if the user changes the value in column 1 from 2 to 1 and the value in column 5 had been 60 - the cellbackcolor of column 5 for the row is red.  Since column 5 can not get the focus now - I can't change the cell back color

Is there anyway of changing a cells backcolor without activating cell enter?

Changing Cell Colors
Hi folks, I'm a beginner using VB and here's what I'm trying to do. In Excel, I want to change the background color of a particular cell based on a numeric that shows up in another cell. My application needs to 5 different colors so I don't think the conditional formating feature can do it.

Mshflexgrid Cell Colors
I want two background colors one for each row in the mshflexgrid control.
e.g. row 1 = red, row 2 = green, row 3 = red, row 4 = green

Any suggestions?

How To Keep Flexgrid Row Colors Depending On Cell Contents
hey peeps,

i have the following code to scan a flexgrid, and depending if the contents of a cell match a scannedcode, the row colour changes from red to green.

the code works (sort of), but everytime a new scannedcode is searched and found, the green row simply moves... I need the flexgrid rows to STAY green as more scannecodes are found in the table.

grrrr.... I do understand _why_ the row color keeps moving, but i can't understand how to work around it!

please help!

Private Sub codefound(scannedcode, numtotallines)
Picresult.Print "FOUND"
Dim lrow As Long, lcol As Long
Dim lcolor As Long

'stockview.Redraw = False

For lrow = stockview.FixedRows To numtotallines
stockview.Row = lrow
If stockview.TextMatrix(lrow, 1) = scannedcode Then
lcolor = vbGreen
Rem Else: if stockview.backcolor = vbRed then
Else: lcolor = vbRed

End If

For lcol = 0 To 1
stockview.Col = lcol
stockview.CellBackColor = lcolor
Next lcol
Next lrow

'stockview.Redraw = True
End Sub

How Do I Change Cell Colors In The Datagrid Control
Alright I have a datagrid thius I am populating dynamically based upon the users input. what I want to do is look at a specific cell and based upon that cell's value change that row's text color(.forecolor) . Does anyone have a clue on how to do this???

MSHFLEXGRID Jump To Cell And Form Colors
Hey All. I Have A Couple Questions, First During Runtime How, In A FlexGrid, Can You Have The Focus Of The Cell Jump To Another Cell. For Example You Are In Cell 1, 1 ; And I Want To Jump To Cell (4, 5) After A Keystroke. And For My Second Question, Is There Any Way To Change The Colors Of The Title Bar On A Form And Also For Instance The Highlight Of A Combo Box, List Box Or Text Box????? Any Reply Would Be Greatly Appreciated.


MSFlexGrid Alternate Row Colors

Can MSFlexGrid have alternate row colors? I see the .BackColor will set a color for the entire grid but I can't find a property for a particular row. Is there such a thing?


Flashing Colors In MSFlexgrid

In a VB6 MSFlexgrid, I would like to give a particular row a flashing color.  Is that possible and how can I achieve this?

Many thanks and greetings from Brugge (Bruges - Belgium),


How To Display Text In MsFlexgrid In Two Colors

  I am displaying a calendar in MsFlexgrid Control, i check the database and if the record is for a date - then i will place some information in the Cell {Date Column in MsFlexgrid} , but the space is not enough, i put the request here and tried whether is there any way to provide the ScrollBar inside a Cell in MsFlexgrid. I think its not possible. I get the replies to increase the height of the row, but increasing some of the row height will not look good in a Calendar. The user also use to take print out of it.

For example i need as below - Is it possible to do it in a single Cell in MsFlexgrid.

Quote:Start Date: 0/22/2006
Eqp Name: Sulphur TR3

Click Here For Detail


RESOLVED Need To Place Text In MsFlexGrid Cell, It Should Append If Cell Already Have Text
Hai ,

i exactly need the logic i think so
If i am populating the grid within the While Statement and the For Loop,

for the first time with this code i am able to place the information in the Cell, but for the second time i am not able.

There may be a chance of having two records with the same date at that time i need to append the information with the existing content in the grid , but if its going to put the information for the first tiem then it should remove the existing date in the Cell. Currently i tried with this code. its not working. Can any one help me to clear this.

Code:SQL = "select * from NewAssg where TIEtsOspas between #" & Month(lsFirstDate) & "/01/" & cboYear.Text & "# And #" & Month(lsFirstDate) & "/" & Day(DateAdd("m", 1, lsFirstDate) - 1) & "/" & cboYear.Text & "#"

rst.Open SQL, cnnNew, adOpenStatic, adLockReadOnly, adCmdText

If rst.RecordCount >= 1 Then
    While Not rst.EOF
            For iRow = 1 To grd.Rows - 1
                For jCol = 1 To grd.Cols - 1
                     If Format(Month(rst.Fields("TIEtsOspas")) & "/" & grd.TextMatrix(iRow, jCol) & "/" &             cboYear.Text, "mm/dd/yyyy") = Format(rst.Fields("TIEtsOspas"), "mm/dd/yyyy") Then
                           grd.Row = iRow: grd.Col = jCol: grd.CellAlignment = flexAlignLeftCenter
                           PrvVal = grd.TextMatrix(iRow, jCol)
                           If grd.TextMatrix(iRow, jCol) = grd.TextMatrix(iRow, jCol) Then
                                grd.TextMatrix(iRow, jCol) = "EqpName:" & rst.Fields("EqpName") & vbCrLf & "StartDate:" & Format(rst.Fields("TIEtsOspas"), "mm/dd/yyyy") & vbCrLf & "Duration:" & rst.Fields("DOffStrm")
                                grd.TextMatrix(iRow, jCol) = grd.TextMatrix(iRow, jCol) & vbCrLf & "-------- x -------" & vbCrLf & "EqpName:" & rst.Fields("EqpName") & vbCrLf & "StartDate:" & Format(rst.Fields("TIEtsOspas"), "mm/dd/yyyy") & vbCrLf & "Duration:" & rst.Fields("DOffStrm")
                           End If
                     End If
End If


Edited by - chs on 7/4/2005 12:41:45 AM

MSFlexgrid Cell Wordwrap
As I type in text into a cell in MSFlexgrid, I want the cell height to expand and show the type matter in the subsequent lines. Is this possible? If so how?

Please help


Size Of Each Cell In MSFlexgrid

I am using MSFlexgrid to display the requested data from my database. I would like the users to see all the data displayed in each cell, however now because each cell has a fixed size (I think!) it doesn't show all the data but shows as far as it can.

How can I change it so that it would let the user to see all the data, but I don't want to set the size of each cell to the max length of data I have. I want to make it like Access where there are fixed size of cells but still u can see all the data.

Anyone have an idea?


Copy Cell Value From MSFlexGrid
Does anyone know how to copy a cell value from a FlexGrid?

If I highlight the cell and press Ctrl+C, it won't work. FlexGrid is not editable so I don't know how to copy the cell's value.



Cell Coordinates Of MSFlexgrid
hello people
its the first time i have joined any such forum. so please forgive me if my query is overly naive ... (a euphimism for 'stupid') .
i am trying to take input in MSFlexGrid. i came to know the trick of placing an input control (Textbox or combobox) on the grid from a post on this forum (i googled for it anyway). But the solution provided here positioned the grid on 0,0 location, and the Textbox would surface on RowColChange event of the grid. now that i want to change the position of the grid on the form, the textbox is appearing on locations as if the grid is still on 0,0 position. The code i consulted from this forum would move the textbox according to the .CellLeft and .CellTop attributes of the grid. But i have found that the CellLeft and CellTop attributes return the same values, no matter where i position the grid on design time. they appear to return values as if the grid is positioned at 0,0. To cut the long story short, IS THERE ANY WAY I CAN GET THE CO-ORDINATES OF THE SELECTED CELL OF MSFLEXGRID? the CellLeft and CellTop properties dont seem to help.


MSFlexGrid - How To Edit A Cell.
I trying to use an MSFlexGrid to present and edit some tabular data.
The grid is NOT connected to a data source.

I can fill the grid with data using the .TextMatrix property. However,
I can not figure out how to make the MSFlexGrid allow me to edit text in a cell. There must be as switch to turn this on, but I can not find it.

I want the cell I select e.g. double click on to highlight the content and allow me to overwrite what ever there is in the cell.

Can anyone tell me if it is possible to do this, or if I have to program this behavior, e.g. showing a textbox on top of the selected cell to give the impression of editing the content.


Multiline For A Cell In Msflexgrid
How to make (or is there a way to make) a cell/cells of msflexgrid multiline text, like <Text1.MultiLine=True> ?

Merge Cell In MSflexgrid

Is there a way to merge cells for the first one or two rows only (not the whole MSflexgrid)?

MSFlexgrid Use Cell Data In VB
I have a MSFlexgrid on a form. The data in the flexgrid are automatically loaded from excel. Now i want users of my application to be able to select a row by clicking the row, and specific data in that row should be automatically transfered to a textbox so that they can be processed in a calculation etc. Please help me with this one. I have searched all over the net to find a solution. (VB6)
When I say clicking on a row (or a cell) I mean a row in the flexgrid not excel.

Select Cell In MSFlexGrid

I have an app that displays data in an MSFlexgrid. One column displays sample number, others display data. Since there are many records for each sample number, the sample number column mergecell option is turned on. I need to be able to click on that value (which selects the cell in "flexSelectionFree" mode) and be able to capture that text (the sample number) to use elsewhere. In other words, I have another form where I want to make a db call that essentially says "display picture where sampleID = 'SELECTED TEXT FROM FLEXGRID'.

Can anybody tell me how?

Thanks in advance

MSFlexgrid Cell Calculation Help
Say I have a MSFlexgrid with 3 columns (price, quantity, and cost). Cost = price *quantity.

The price and quantity data is fed in from a server and is updated frequently. What is the best way to get cost to automatically update whenever price or quantity changes at each particular row? Keep in mind that the user will not update the price and quantity manually, so having the cost column update when the user presses return will not work.

Merge Cell In MSflexGrid
how can i merge row together? I tried to use the .MergeCells = flexMergeRestrictRows in design mode, but i still cant make it work...Why is this so?

Format MsFlexGrid Cell's

I want to format cell's data amd thin export the data to textbox

what i missing is how to format the cell's


With fg1

'First Row

.TextMatrix(1, 0) = "1"
.TextMatrix(1, 1) = "2"
.TextMatrix(1, 2) = "6"
.TextMatrix(1, 3) = "4"

'Second Row

.TextMatrix(2, 0) = "5"
.TextMatrix(2, 1) = "6"
.TextMatrix(2, 2) = "7"
.TextMatrix(2, 3) = "8"

End With
Know what i need is when i hit a command button to check the cell's then format the data to textbox to be Somthing like that

' First Row


'Second Row

I hope i make it simple

MSFlexgrid Cell Calculation Help
Say I have a MSFlexgrid with 3 columns (price, quantity, and cost). Cost = price *quantity.

The price and quantity data is fed in from a server and is updated frequently. What is the best way to get cost to automatically update whenever price or quantity changes at each particular row? Keep in mind that the user will not update the price and quantity manually, so having the cost column update when the user presses return will not work.

Select Next Cell In MSFlexgrid
I have a MSflexgrid set up where I can enter data using the textbox overlap trick. This is working fine. After I input the text and press enter, the active MSflexgrid cell remains selected. How do I get it to select the next cell directly below it on the next row?

It should work like how Excel automatically puts the cursor on the cell directly below the active cell after you press return.

I believe the code in Excel VBA would be activecell.offset(1,0).activate. I need the equivalent for MSFlexgrid.


Cell Editing In MSFlexgrid

I have used FlyGuy's code under 'More advanced in cell editing ' title to be able to let the users to see the whole content of my data grids.

I have been using SSTab to develop my application, I have 3 tabs, all having data grid on each of them.

Now I have used different textboxes and different variables for identifying the rows and coloumns in each data grid and the code is working fine.

The only problem I am having is when I am switching between the tabs, the cell I have chosen from the previous tab can be seen in all the data grids. I do initiliase the textboxes to " " and rows-coloumns used in each data grid to -1 however it makes no changes

How would I solve this problem. Any ideas?


MSFlexgrid Cell Selection
Hi i wonder if someone can tel me how can i do a multiple cell selection in MSFLEXGRID like the one in the attachment. I tried the selection mode but will not do it.

Thanks for the help.

MSflexgrid Cell Location
I want to place the cursor on a particular cell in the flexgrid.Can someone help me with this.


Msflexgrid Cell Disable
How do I enable and disable editing of specific cells in a msflexgrid?

MSFlexgrid- How To Setfocus To A Particular Cell
When my focus is in a particular cell, i want it to display a particular value, that is to multiple 2 values and display it.
How do I do it.

I used this code of the forums to write in a flexgrid.

VB Code:
With MSFlexGrid1         Select Case KeyAscii            Case 8                If Not .Text = "" Then                    .Text = Left(.Text, Len(.Text) - 1)                                                      End If            Case 9 ' Tab                If .Col + 1 = .Cols Then                    .Col = 0                    If .Row + 1 = .Rows Then                        .Row = 0                    Else                       .Row = .Row + 1                                            End If                Else                    .Col = .Col + 1                                    End If            Case Else                                                    .Text = .Text & Chr(KeyAscii)            End Select                                                If .Col = 8 And KeyAscii = 13 Then               .Rows = .Rows + 1                         End If    End With

Color Cell With MSFLEXGrid! Pls Help Me!
Hi all,

With one value for 1 cell want to set one color. Mean: if me.MSFLEXGrid.textmatrix(col, row)='A' this cell has red color
elseif me.MSFLEXGrid.textmatrix(col, row)='B' this cell has Blue color. What should I do? Please help me to solve this problem.

Thanks in advance.

Msflexgrid Delete Cell
how would i go about deleting a cell that the user has selected? i have a grid of pictures and want to be able to click on a certain cell, hit the delete button and empty the cell. any calls on this one? thanx

Msflexgrid Cell Size
Hello everyone

Am back .... yeah again with a question ... hope you can solve it

I want to set the size of the cell of msflex grid ....

I tried to use

Msflexgrid.cellwidth = 1000

but it gives me an error ....... plzzzzzzzzzzzzzz i want to do it immediately ................ help meeeeeeeeeeeeee

Harris Moin

Highlighting Cell In MSFlexGrid
Hi. Can you please tell me how I can highlight a cell in a MSFlexGrid using code? Thanks. (Yes another highlighting question

Pictures In An MSFlexGrid Cell?
What is the correct syntax for putting pictures in MSFlexGrid cells?


Editing A Cell In Msflexgrid

im using the follow code to edit a cell in flexgrid. i put a textbox with visible property to false and when i click on the cell, start this code:

Private Sub flexgrid1_Click()

Text1.Visible = True
Text1.Top = fg1.Top + fg1.CellTop
Text1.Left = fg1.Left + fg1.CellLeft
Text1.Width = fg1.CellWidth
Text1.Height = fg1.CellHeight
Text1.ZOrder 0

End Sub

the textbox appears, but at wrong place, above and left from clicked cell.

can anyone help me??


The Text In A Msflexgrid Cell Is Cut Off
If the text in a msflexgrid cell is longer than the column width, my text is cutoff. I don't want to use word wrap. How can I get the column width set so my text is not cut off? And I want to have the scroll bars too.

Thanks in advance,

MSFlexGrid Cell Color
Does MSFlexGrid have a property or method so that I can
set different color for one cell and another color for another cell? Please help! Thank you...

How Do You Tell What Cell You Are Over In A MSFlexGrid On MouseMove?
Just a quick would you tell which cell you are over in a MSFlexGrid in a MouseMove event?

Can you get the specific row and col?

Thanks for the help

MSFlexGrid, Disable Cell
I would be grateful if anyone could shed any light on how I might be able to disable a particular chosen cell in an MSFlexGrid. Thanks very much in advance for any replies.


VB6 MsFlexGrid Cell Border
Can I set borders for a cell or a row by VB code? How?

Msflexgrid Cell Resizing
I have looked through tons of posts and FAQs and, I still have not found how to resize a cell within an MSFlexGrid.  If anyone could point me in the right direction whether it was handled in a previous post or if you could just explain it to me, it would be greatly appreciated.  Thanks.

Tooltip On Msflexgrid For Each Cell

I'm playing with the msflexgrid. It's filled with some data, but data is too large to show in a cell completely.

I'm trying to have this flexgrid showing the content of the cell while moving over by showing a tooltiptext. It should work like that without having to click on the cell.

If I clicked on a cell, it is working, but not while moving the mouse to another cell.
Can anyone helps me starting this thing ?

Kind regards...

Outline A Cell In MSFlexGrid

I'd like to outline the current cell in an MSFlexGrid control with a
certain color and line thickness. I thought of putting a shape control
on the form and positioning it over the cell, but the shape control is
always behind the grid (and therefore hidden). Does anyone have any
ideas about how to do something like this?

Also, do you know of any grid controls that allow in-cell editing?


Michael Floyd

Highlight Cell Of MSFlexgrid
hi all

I am using MS Flexgrid to display data..
Well I am able to highlight particular cell
but for some critical values i need that
the backcolor of the particular cell should
get 3-4 color one by one......colorful blinking

how to do this...pls help

thanks in advance

MSFlexGrid - No. Of Character A Cell Can Contain??
Hello all,

How to find the number of characters a MSFlexGrid cell can contain, Knowing the MSFlexGrid1.ColWidth() of a column??

I know we can find the TextWidth using
Me.TextWidth(Trim(MSFlexGrid1.TextMatrix(lRow, lCol)).

Assuming a default fontsize.

Please Help!

with regards

Max Cell Limit For A Msflexgrid
Hi All,
I used a msflexgrid to display a data retrieved from the database..

Me.msflexgrid1.ColWidth(0) = 2200 'stepName
Me.msflexgrid1.ColWidth(1) = 2200 'startTime
Me.msflexgrid1.ColWidth(2) = 1800 'userId
Me.msflexgrid1.ColWidth(3) = 1800 'reasonCode
Me.msflexgrid1.ColWidth(4) = 1500 'category
Me.msflexgrid1.ColWidth(5) = 1500 'quantity
Me.msflexgrid1.ColWidth(6) = 2200 'sourceLots
Me.msflexgrid1.ColWidth(7) = 2200 'targetLots
Me.msflexgrid1.ColWidth(8) = 5000 'description
Me.msflexgrid1.ColWidth(9) = 35000 'comment

the last column shud display comments value which a very very long text..
however, when i run this project, the comment column did not display full contents retrieved from the dbase..

is there any max limit for text that can be displayed in a cell?

anyone have idea how to solve this?

MSFlexGrid Cell BackColor
Hi all,

Can I change the backcolor of individual cell on the MSFlexgrid? I just want to change back color for particular CELL, not the whole ROW when that row got focus.

Example: my grid has 4 rows and 4 columns. I want cell (Row1, Col1) to be red, cell(Row 2, Col2) to be Green and cell(Row 3, Col3) to be Blue.

Please help.


***Sorry, but I found it in the SEARCH

Copyright 2005-08, All rights reserved