xBrowse Back colour of a column based on the column value.

xBrowse Back colour of a column based on the column value.

Postby anserkk » Mon Jan 11, 2010 10:02 am

Hi,

How do I change the Background colour of a column based on a the column value.

The following code is giving error
Code: Select all  Expand view
Error description: Error BASE/1004  Class: 'NIL' has no exported method: EVAL


Code: Select all  Expand view
@ 0,0 XBROWSE oBrw ;
    OF oWnd ;
    FOOTERS CELL

oBrw:oRs:=oRecSet  // ADO RecordSet
For i:=1 to len(oBrw:aCols)

    MsgInfo(Eval(oBrw:aCols[i]:bStrData))  // Error occurs at this point

    // Trying to assign column back colour based on condition
    if Eval(oBrw:aCols[i]:bStrData) > aBranchTemp[i][3]
        oBrw:aCols[i]:bClrStd:={ || {CLR_RED,CLR_GREEN} }
    Endif
Next  


Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: xBrowse Back colour of a column based on the column value.

Postby nageswaragunupudi » Mon Jan 11, 2010 12:47 pm

Please see the following sample code:
Code: Select all  Expand view
  @ 0,0 XBROWSE oBrw OF oWnd ;
      COLUMNS 'col1', 'col2' ;
      RECORDSET oRs CELL FOOTERS

   oBrw:Col2:bClrStd := { || If( oBrw:Col2:Value > n, { CLR_BLACK, CLR_WHITE }, { CLR_WHITE,CLR_RED } ) }
 


The above code sets color of the column with header 'Col2' as { CLR_BLACK, CLR_WHITE } when the cell's value > n and otherwise to { CLR_WHITE, CLR_WHITE }.

1. Please avoid using :bStrData directly in your code either to assign or to find its value. Let us leave bStrData to be used by XBrowse internally. You may find some postings in these forums using bStrData directly. That kind of usage is very obsolete and results in (a) not using XBrowse to its full power and (b) problems like this.

Instead use oCol:Value to find the cell's value.

If we allow xBrowse to construct the browse for the recordset by specifying column names XBrowse takes care of all the values properly.

In case we need set the codeblocks for a column ourselves, assign the codeblock to :bEditValue and the picture clause to :cEditPicture. XBrowse constructs internally bStrData to be something like { || Transform( Eval( oCol:bEditValue ), oCol:cEditPicture ) }.

2) Please also try to avoid using column numbers in our code. Column numbers change dynamically at runtime, when the user swaps columns. Even otherwise future mainenance of the code may become difficult when we change the order of columns or drop or add some columns in future versions.

Instead better to refer to the column object by its header name as oBrw:oCol( <cHeader> ) or oBrw:<cHeader>. Code is more readable and also easier to maintain in future.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Back colour of a column based on the column value.

Postby anserkk » Mon Jan 11, 2010 4:08 pm

Dear Mr.Rao,

First of all let me thank you for providing a very detailed explanation and guidance on the proper usage of xBrowse. You are a real master of xBrowse. :)

Many novice users of FiveWin, like me may not be aware of the proper usage of the FiveWin Classes and fail to extract/utilize the 100% power out of these classes.

I have very well noted all the points which you have suggested :) I shall test your suggestion tomorrow morning.

I am creating recordset's columns dynamically based on the user's choice. For eg. the columns like ItemCode, ItemName will be the minimum columns in a recordset. After that the user has the choice to add columns further, for eg. Location1_Qty, Location2_Qty etc. . Based on the user's choice I generate the SQL statement dynamically and then the recordset.

On the XBrowse's oBar, further I give choice to the user via a DbCombo to choose to display either the stock quantity or the stock value and the recordset is further recreated. For this reason I have referred xBrowse columns by col number. After reading your suggestions, I feel that I should redesign the way I have written the code.

May I ask your advice. As I said above, I change the recordsets dynamically using the DbCombo on the xBrowse's oBar. When I change the contents of the recordset I loose all the column width settings, Column totals, oBrw:oSeek etc. and I have to re-do the settings again through a function. Is this the expected behavior or am I doing something wrong. The xBrowse is on a window and not on a dialog.

Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: xBrowse Back colour of a column based on the column value.

Postby nageswaragunupudi » Mon Jan 11, 2010 5:15 pm

Mr Anser

I see that you want to allow the user to select the columns that are to be displayed. The approach you are adopting is that you are reading only those selected columns from the table. I agree that reading only the required columns against reading all columns from the table is theoretically faster than reading all the columns. But the difference in speeds and burden on the server or network traffic may not be perceptible in many cases of medium sized tables.

I propose this approach:

1) Construct SQL and populate the recordset with all columns that the user has choice, leaving out the columns that are never to be shown in the browse.
2) Construct the browse with all columns, by using AUTOCOLS clause of XBROWSE command.
3) Hide columns that are not yet selected and show only columns that are anyway to be shown, ( oCol:lHide := .t. ) before activating the dialog / window.
4) Offer the user a combobox selection to display or hide the columns as per his choice. In fact you do not have to make this feature yourself. XBrowse has a built-in facility for this. If the user right clicks on headers, a menu appears with all the columns allowing him to hide and unhide the columns of his choice. Please try this feature by right clicking on any xbrowse header. If you offer this feature, this is the standard way for all browses accross the application. ( you can disable this feature by oBrw:lAllowColHiding := .f. )

Please test my approach and I am sure you will not be disappointed. You may also be surprised that you can write the entire module within less than half a page of code with all the interface you have in mind. You save the time to write the code and maintenance.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Back colour of a column based on the column value.

Postby nageswaragunupudi » Mon Jan 11, 2010 5:22 pm

Personal note to Mr Anser

We live in nearby cities. If you don't mind, I would be glad to be in touch with you. My email id is nageswaragunupudi@gmail.com and my phone is +91 9848046726. There could be a lot for us to learn from each other.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Back colour of a column based on the column value.

Postby anserkk » Tue Jan 12, 2010 5:17 am

Dear Mr.Rao,

Thank you very much and glad to be in touch with you. I have send you an email

Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: xBrowse Back colour of a column based on the column value.

Postby anserkk » Tue Jan 12, 2010 11:17 am

Dear Mr.Rao,

What would be the code to change the color of a cell based on the value of the cell. I made a mistake while raising the query. I asked the code to change the xBrowse back colour for a column, in fact my requirement was to change the back colour of a cell based on the value of the cell.

I tried your above code. It is working fine but the whole column's back color is getting effected based on the 1st row's value of each column. Sorry for the confusion :oops:

Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: xBrowse Back colour of a column based on the column value.

Postby anserkk » Tue Jan 12, 2010 12:22 pm

Hi,

Solved the issue

Code: Select all  Expand view
oBrw:bClrStd := { || If( oBrw:Col2:Value > n, { CLR_BLACK, CLR_WHITE }, { CLR_WHITE,CLR_RED } ) }


I was using the alternative row colors (Pijama effect). Now I should find a simple way to display the xBrowse with alternative row colors (Pijama effect) and change only the back color of the cell to red only when a particular condition is met.

Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: xBrowse Back colour of a column based on the column value.

Postby nageswaragunupudi » Tue Jan 12, 2010 1:44 pm

Pajama Effect:
Code: Select all  Expand view

oBrw:bClrStd := { || If( oBrw:KeyNo() % 2 == 0, aClrPair1, aClrPair2 ) }


Pajama Effect + Conditional
Code: Select all  Expand view

oCol:bClrStd := { || If( lCondition, aClrPair3, If( oBrw:KeyNo() % 2 == 0,  aClrPair1, aClrPair2 ))}
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Back colour of a column based on the column value.

Postby anserkk » Tue Jan 12, 2010 3:51 pm

Dear Mr.Rao,

Thank you. Solved the issue with similiar logic. I was just trying to make sure that there are no other methods to achieve the same and that I am following the right path. Many times we may not know that there exists some methods/tricks in xbrowse to achieve the same, and without knowing it we may complicate our code.

Regards
Anser
User avatar
anserkk
 
Posts: 1331
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 42 guests