Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange behaviour of gird with invisible column

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I just came across this interesting problem, and I thought I'd share the solution in case anyone else comes up against it.

A client reported that his grids were acting strangely. If the user makes a column wider, and if, as a result, a horizontal scollbar appears, strange things happen.

In particular, right-scrolling the grid causes the columns to "break up"; sometimes you see a spurious blank column, and sometimes a column is repeated. If you click somewhere in the grid to move to a different record, some cells seem to move to a different column.

After a little trial and error, we found the cause. The problem only occurs when the grid contains an invisible column, that is, one whose Visible property is .F.

We fixed it by changing Visible to .T., setting the column's Width to 0, and making the column non-resizable. Once that was done, the strange behaviour went away.

That said, I'm not sure why the grids needed to contain an invisible column. If you don't want to show a certain field, it can simply be excluded from the grid. We ended up doing that.

So, just in case anyone comes up against the same issue, that's how to fix it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike,
was the invisible column on the far right, left or in the middle of other columns? I use lots of invisible columns but they have aways been far left (No special reason other then that is what I have always done.) Anyhow I have never seen the odd behavior that you described and I wonder if making the columns the first (Far left) is another possible fix?


Lion Crest Software Services
Anthony L. Testi
President
 
MrDataGuy = "I use lots of invisible columns but they have always been far left"

Are they dynamically 'invisible'?
Meaning are they sometimes visible and other times invisible?

Otherwise why would you include them in the Grid at all?
You can specifically include the fields/columns that you need in the Grid and just leave the others out.

For one client I had a control table which was used to dynamically build the grid and utilize the column-specific settings. That control table 'informed' the grid build routine which columns to include and which to leave out. In that way I never had to have 'invisible' columns.

Mike - thanks for the heads-up.

JRB-Bldr

 
Are they dynamically 'invisible'?"
No (Well I build the grid at run time, and may refresh the whole grid later but each time the columns are kept invisible.)

Why, well the column changes I can access this 'hidden' information on the current row. Heck I am nor sure that doing this now is a good or wise ide, but I have done it and it works.

One point I should make is that I use grid 99% of the time as a read only display device. I put textboxes etc on the form to allow the user to make needed data changes. I have been bitten to often in the past trying to handle in the grid all of the Biz rules that come up and refresh issues.

Lion Crest Software Services
Anthony L. Testi
President
 
MrDataGuy - "Why, well the column changes I can access this 'hidden' information on the current row"

Just because your Grid is not displaying a table/cursor field ('invisible' or not) doesn't mean that you cannot access the field's contents - as long as the field exists in the table/cursor.

Good Luck,
JRB-Bldr
 
What jrbbldr says, you can access the cursor - and you should instead of accessing the column.text1.value.

You can get rid of such columns at runtime by setting their columnorder to the columncount and then reduce the columncount. Or you don't generate these columns at all in the first place.

Bye, Olaf.
 
What jrbbldr says, you can access the cursor - and you should instead of accessing the column.text1.value"

I Agree with you both!

However as Fox allows you to do things in so many ways I do (did) sometimes access the information in the grid proper instead of the underlying cursor. I went and looked at some code and I realized that I have been looking at the under lying cursor information for code I wrote in the last ~3 years, but older code I did have hidden columns and accessed the data via the grid itself. Guess I changed styles with out even being aware of it.

Note: I have been working with the dBase language since 1986 and I think I have made most of the possible mistakes at one time or another, a most likely continue some to this day. (I can recall wondering why one needed more then one table/cursor open at a time, and what the big deal with this "SQL SELECT" command is, since you could hand code any SQL statement yourself using basic xBase commands. <Smile> )

Lion Crest Software Services
Anthony L. Testi
President
 
Anthony and JRB,

To answer your questions:

- The column in question was always the left-most one.

- The column was not added dynamically, but the Visible property was set dynamically, in the grid's init.

Personally, I've never seen the need to have an invisible column in a grid. In this case, it was being used to store the record ID ((which the user doesn't know about). But if I need to relate an ID to a row in the grid, I would do so by retrieving it directly from the underlying cursor.

That said, I would have thought that making a column invisible wouldn't be all that unusual, so it's surprising that this issue isn't better known.

Anyway, thanks for your comments.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top