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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi line grid field condition 2

Status
Not open for further replies.

Phil Thoms

Programmer
Oct 31, 2005
245
GB
Hello,
I have a multi line grid that I created in VFP6 (YES a multi line grid) it works superbly and is accessed on a daily basis with new data.
However, I wish to place a condition on a table field called quantity. When the quantity field is greater than 1 then I would like it to display in red.
I know this is straight forward in a normal grid with dynamic properties but I can't manage to achieve it in my multi grid.
For your information:-
I have constructed the multi line grid with several text fields inside a container with control sources from a table, the container has then been bound to a column within the grid.

Your help would be gratefully received.

Thanks.
 
Mike, The code as in the method:-

If atest.ID='1001'
this.text1.forecolor=rgb(100,200,100)
else
this.text1.forecolor=0
Endif

RETURN THIS.backstyle

If atest.qty>1
this.text2.forecolor=RGB(255,0,0)
else
this.text2.forecolor=0
Endif

RETURN THIS.backstyle
 
Maybe as simple as ALLTRIM(atest.ID)=='1001', you might have either leading space, or you have exact on and trailing space - which is very usual for char fields.

Bye, Olaf.
 
Olaf,
One point I didn't make is that the first set of code for text1 produces a green ID which is correct BUT the second set of code for text2 doesn't work at all. If I try the second one on its own it works OK. Mystery.

Thanks
PT
 
Well, I think you just need to remove the additional RETURN, every code after a RETURN simply doesn't run.

Bye, Olaf.
 
Mike and Olaf,
Yes, I overlooked this, now works fine.
I assume one can use an infinite number of conditions in this access method?

Thanks once again,

PT.
 
Well, "infinite" might be an exaggeration. But, yes, you can use as many conditions as you like, and set any combination of properties. This is just normal method code, pretty much the same as you would write anywhere else.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, you can have anything in one place, the main controls backstyle_access code.

The idea to use each control itself still is valid and both strategies have their pro and con, of course. Since this is the only "event" happening (the grid only reads its columns current contol backstyle, not every backstyle of child controls like these in the container), at least calls into each detail control will need to go in the container. What could also be used is BINDEVENTS to bind each single control to the outer containers backstyle_access method and also get each single control triggered in some method you decide as event delegate.

Grid.Column1.YourContainer.Text1.Init could do Bindevent(This.Parent,"backstyle_acces",This,"Change"), when you define a textbox class and add a user defined "Change" method. Or bind it to "ProgrammaticChange", for example. Or you do as I did and in Grid.Column1.YourContainer.Backstyle_Access do a call of THIS.Text1.Change(), the Bindevent just has the advantage it acts on itself, everything is encapsulated in the Text1 box and only makes use of the backsty_access, whic in itself then only needs the RETURN This.Backstyle.

One place for all is fine for an overview, but there is a reason for OOP principles like encapsulation. Each control may have different means to highlight itself, you might want to encapsulate this into each control type instead of one central code and once you have your control classes, this mechanism can be reused in different forms/grid with different combination of the single fields/controls. Reusability of the same highlighting of single controls would speak for going further with base control classes, including writing a grid class, which mainly has one column with a container having the inner details of a record to show. It's a good idea to have base classes and not use the native base class to have such points to define base behaviour.

Bye, Olaf.
 
Mike and Olaf,
Very useful informations. I hope more programmers will want to develop these multi line grids, they look more professional than a very wide form containing a grid with many columns that can become awkward to read. Trawling through many previous threads I see that not many years ago the multi line grid was considered a "no no".

Thanks for imparting your knowledge.

PT
 
Well, such a construct of a container of course disables you from using grid behaviour you only have with multiple columns, eg the only Before/AffterRolColChange events will be row changes, you only have one column, changing focus from Text1 to Text2 within a row doesn't cause such an event. Everything has its pros and cons. It depends what you do and want from a grid, whether using it in this unnatural way is good or not, but surely a container in a grid column is the only good way to have multiple rows of controls within one grid row or for each single table record, or any type of layout you want and can design in a container. So it's VFPs way of MS Access Subforms, if you look at it this way.

So I don't know what old discussion you refer to, I can only assume the outset for that specific discussion was different.

Bye, Olaf.
 
Olaf said:
What could also be used is BINDEVENTS to bind each single control to the outer containers backstyle_access method

Olaf, PT is using VFP 6.0. If I remember right, BINDEVENT() was introduced in 8.0.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for reminding, Mike. So the only solution for VFP6 would be to make the explicit calls, eg in the backstyle_access do call

Code:
This.Text1.Change()
This.Text2.Change()
Return This.Backstyle

And then have the details of what to do in each control itself. One other way of generalising it would be using
Code:
For Each loControl In This.Objects
  If PEMSTATUS(loControl,"Change",5)
     loControl.Change()
  Endif
Endfor
Return This.Backstyle

Which would call every Change method of any inner control within the grid column container.

And another "classic" (also doable in VFP6) way to cascade one event to many calls is to use SetAll(), as you already did with the Forecolor property. You could also use SetAll to set a user defined property, add an assign method (like you did add the backstyle_access method) and put in any code you want in that besides or instead of setting the property value.

Bye, Olaf.
 
Mike,
Just round off this thread, I have found a copy of the Doug Hennig paper on Access and Assign methods as per your suggextion.

Thanks,
PT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top