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

Changing color of selected column 2

Status
Not open for further replies.

jbeetz1

Programmer
Nov 28, 2000
60
US
Is there a way to change the color of the selected column of a row of a datawindow. For example if field1 selected background color = yellow, else = white
 
Add this code to itemfocuschanged event of the datawindow

long ll_columns,ll_i
string ls_colName
ll_Columns = Long(this.Object.DataWindow.Column.Count)

FOR ll_i = 1 TO ll_Columns
ls_ColName = this.DESCRIBE( "#" + String( ll_i ) + ".Name" )
if (ls_ColName = string(dwo.name)) then
this.Modify(ls_ColName+".Background.Color='11665407'")
else
this.Modify(ls_ColName+".Background.Color='1090519039'")
end if
NEXT

 
It works fine execept for one thing that I failed to mention. I display multiple rows and I only want to change the color of the column for one row not all rows. I think I need to put the code in as an expression for the backgound color in the datawindow painter, but I haven't been able to figure out how to get it to work.
 
Try

if( isSelected(),RGB(255,0,0),RGB(255,255,255))

or similar in the background color property of the column.
 
I tried the IsSelected()function but that selects the entire row. What I have is a datawindow with 4 columns and multiple rows. When the user clicks in a column I want to change the background color of that column for that row only.
 
Even as of PowerBuilder 9, this is NOT possible by using a 'simple' dw expression because there is no GetColumn() or GetColumnName() datawindow-function whereas there is a GetRow() dw function!!! Hope Sybase realizes the need of this function and offers it in future.

The only way to achieve this effect is to write a global function (in fact, a couple of functions) and use them in the dw-column's expression:

////////////////////////////////////////////////////////

FUNCTION string f_GetColumnName()
RETURN gs_ColumnName


FUNCTION f_SetColumnName( string as_ColumnName )
gs_ColumnName = Trim( as_ColumnName )


Ancestor dw.ItemFocusChanged! event:
-----------------------------------
f_SetColumnName( dwo.Name )


dw Column.Background.Color attribute (expression):
-------------------------------------------------
If( f_GetColumnName() = &quot;<col>&quot;, RGB( 128,128,128 ), RGB( 255,255,255 ))

////////////////////////////////////////////////////////

You may use the STANDARD Windows' hilite color such as the Navy Blue for the hilite color by querying the Control Panel: HKEY_CURRENT_USER\Control Panel\Colors that can be written as another global function to parse the values and return the long color value to use in the column's expression.

Hope this helps...

---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group
 
You don't need a global function; you were on the right track with an expression in the background color property of the columns in the datawindow(s) you want to have this functionality. Use: if( isSelected(),RGB(255,0,0),RGB(255,255,255)) and substitute the correct RGB values for the colors you want.
 
Just for the record Powerobject's solution was the only one that workded. mbalent's solution would of worked except that there are multiple rows displayed and I only wanted to change the color of one column in one row.
 
(dw constructor)
...
ls_cambia_color = &quot;DataWindow.detail.Color= '0~tif(mod(getrow(),2) = 0,&quot; + ls_color + &quot;, &quot; + &
+ &quot;rgb(255,255,255))'&quot;

//ls_cambia_color = &quot;DataWindow.detail.Color= '0~tif(mod(getrow(),2) = 0,rgb(130,255,255), &quot; &
//+ &quot;rgb(255,255,255))'&quot;

this.Modify(ls_cambia_color)

With it u can change the color odd/even rows...
 
The original poster says he wants to hilite only the 'currently' focussed column on the current row (like a cell). I gave a solution that I tested by myself before and that works. However, this not the most perfect solution as the as_ColumnName var has to be stored at the dw-level for each dw. Since this is shared by all the DWs, a dw may not display the currently focussed column on switching between sheets. To overcome this and make it behave normally, simply place this in its GetFocus! event:

// f_SetColumnName( This.GetColumnName())
This.SetRedraw( TRUE )

This will force it to hilite the currently focussed column on the current row at all times.

Hope this helps...

---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group




> mexicomeat (Programmer) Nov 17, 2003
>
Powerobject
> I am rather surprised to your reply pal. Were you
> drunk? :) Just kidding
>
> mbalent's solution works for me.
 
jbeetz1 wrote:
>Just for the record Powerobject's solution was the only
>one that workded. mbalent's solution would of worked
>except that there are multiple rows displayed and I only
>wanted to change the color of one column in one row.

My solution only highlights the selected row/column regardless of whether multiple rows are displayed in the datawindow. If you click on a column and the entire column is highlighted, this is a separate issue
 
Sorry for the delay. I have another group (PowerObject!) with nearly 1500 members and was busy due to hectic activity over there.

> If you click on a column and the entire column is
> highlighted, this is a separate issue.

The original poster says:

--------------------------------------------------
I tried the IsSelected() function but that
selects the entire row. What I have is a
datawindow with 4 columns and multiple rows.
When the user clicks in a column I want to
change the background color of that column
for that row only.
--------------------------------------------------

He wants to hilite ONLY the 'current' column (cell) without having to select/hilite the 'entire' row. Since there is no GetColumn() or GetColumnName() 'datawindow' function, there is no way to code an expression inside the dw to achieve this without using a global function.

Your solution works but we need to 'select' the current row (or turn on the row-selection service) for it to work. My solution works at the 'column' level (hiliting just the current column) without having to select any row.

Hope the above is clear... If not, do try it in your spare time.

---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top