• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:


how do you make a particular cell black? and how can you set the column width so that they are exactly the width of the column header caption?

sorry about the 8 points...thats all I've got
1 Solution
Ok you can make the width of a column by using FlexGrid.ColWidth property set it to the number so it be a good size. Then taking about the background color is not as easy. THe problem as follows. Background is set not for one cell but for all. It can be done i would think for a range of rows. YOu can however set the forecolor of the cell very easily . flexgrid.cellforecolor = vbRed.
To change  any cell color, first you have to set the row and column.

Flexgrid1.Row = 1
Flexgrid1.col = 1
Flexgrid1.CellBackColor = &H00000000&
Flexgrid1.CellForeColor = ....

This will set the 1st row 1st column to black. Likewise you can change the fore color, you can make the cell font bold etc.

I dont think there is anything specific to set the same width as the column header caption. You have set the width during design time by trial & error method only.

You use the formatstring property. It will automatically set the width of the column as same as the width of the text.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

rukimanAuthor Commented:
kudos to selva for the backcolor problem.

I can't use the .formatstring method because I'm getting the information from a database.

The MSHflexgrid has a .colwidth method that sets the column width.

I can make use of  .colheadercaption to get the string in the column header, however how do I find out the number of twips the string takes, so that I can make use of .colwidth method.
Ruki you ignored by answer ? you didnt' read it ?
rukimanAuthor Commented:
sorry marine!
Yes I did read it. But I was hoping I could set it at runtime coz when I'm reading from a database, I can't make any assumptions of the width of the cols.

Gee, the response was great, quite a few people have helped me out,  I don't quite know how to split the few points I have.
rukimanAuthor Commented:
Adjusted points to 18
rukimanAuthor Commented:
Btw, I still wondering about the col width problem :)
colwidth gives  a width for a column here is the example
for i = 0 to msFlex.cols-1
    msFlex.colwidth(i) = 1200
this code will set each column in a grid to 1200 in width
to do only one column or other columns alone you have to do this
msFlex.colwidth(1) = 100
msFlex.colwidth(5) = 700
this will set column 1 and 5 only to specified width.
rukimanAuthor Commented:
Thanks Selva for your help on the background color
and thanks to Marine for the help on colwidth and everyone else who replied!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now