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!

Alter bkgrnd colour of one column in multi column, multi row grid dw?

Status
Not open for further replies.

GreenTreeFrog

Programmer
Jun 15, 2010
7
AU
Hi,

I have a grid datawindow with about 50 columns across and 40 rows down of editable data.

Users can change the value in any of the columns.

I also have an import feature to update some or all of these columns with values from a spreadsheet or Clipboard.

I want to highlight only the columns that have had the value changed whether by import or User manually entering new data... not the whole row nor the the same column in all rows.

So if I change only one column on the whole datawindow, then I want only that column to have a different colour background.

I tired the coding suggestions in this thread to no avail.

Any other ideas?

Thanks!

Melissa
 
Thank you for your reply but I have tried those suggestions.

I don't want to highlight only the selected column.

I want to highlight all columns scattered across the datawindow that have had their values changed.

So it might be one column in one row, then two differenct columns the next row, then none in the next row, then four coloumns in the next row and so on.

So even when they don't have focus, I want their background color to be different to reflect that the new value is different from the retrieved one.

Any other suggestions hugely appreciated thanks!
 
Okay, here we go...

I have a solution of sorts which, once you get it going, will work. It involves:
1) adding a column on the datawindow object
2) populating that column in the itemchanged event
3) putting an expression on the background color property of each visible column in the datawindow object you want the color to change when edited

Sample:
1) I added a column called 'change' (not a computed col)
2)
Code:
//IN THE ITEMCHANGED EVENT
string ls_desc, ls_value, ls_d, ls_prev
integer li_rc

ls_desc =  dwo.name + '.ID'

ls_d = describe(ls_desc)
ls_prev = getitemstring(row,'change')
IF IsNull(ls_prev) THEN ls_prev = ''
ls_value = ls_prev + '[' + ls_d + ']' // append new value
li_rc =    this.setitem( row, 'change', ls_value)
3)
Code:
// in the background color of a column called 'box3'

IF (pos(change[0], '[' + describe('box3.ID') + ']') > 0, RGB(120,0,0),RGB(255,255,255))

Step 3 could be done generically in the open/postopen type event of the window by looping through the datawindow columns and issuing a modify statement tailored to each one. This way if you add a column it will automatically have the functionality.

Matt

"Nature forges everything on the anvil of time
 
Here is code to make things more generic.

Code:
ll_max = Integer(dw_1.Object.DataWindow.Column.Count)  // determine number of columns
FOR ll_i = 1 TO ll_max STEP 1
	// only need the visible columns
	IF dw_1.describe("#" + String(ll_i) + ".Visible") = '1' THEN

	   ls_modstring = "536870912~tIF (pos(change[0], '[' + describe('" +  dw_1.describe( "#" + string(ll_i) +  ".Name") + ".ID') + ']') > 0, RGB(128,0,0),RGB(255,255,255))"
	ls_msg = dw_1.Modify(ls_modstring)
	END IF

NEXT

Matt

"Nature forges everything on the anvil of time
 
Correction to previous post.

This is the correct modify string:
Code:
ls_modstring = dw_1.describe( "#" + string(ll_i) +  ".Name") +  ".Background.Color = ~"536870912~t IF (pos(change[0],~'[~' + describe(~'" +  dw_1.describe( "#" + string(ll_i) +  ".Name") + ".ID~') + ~']~') > 0, RGB(255,255,0),RGB(255,0,255))~""

but I still have issues.

Matt


"Nature forges everything on the anvil of time
 
Thanks Matt. I can see what you are trying to achieve and it is an excellent suggestion. I will see how we go with it.

Thanks again!
 
I found the solution to making it dynamic.
Code in some event when the window opens.

Code:
dw_1.retrieve( )

dw_1.setredraw( False)

// get list of columns in the order they are displayed which may not be the same as their column number order
ll_max = Integer(dw_1.Object.DataWindow.Column.Count)  // determine number of columns
FOR ll_i = 1 TO ll_max STEP 1
	// only need the visible columns
	IF dw_1.describe("#" + String(ll_i) + ".Visible") = '1' THEN
		// first set the mode to opaque 
		ls_modstring = dw_1.describe( "#" + string(ll_i) +  ".Name") +  ".Background.Mode='0'"
		ls_msg = dw_1.Modify(ls_modstring)
		// set the color of the cells
		ls_modstring = dw_1.describe( "#" + string(ll_i) +  ".Name") +  ".Background.Color =  ~"536870912~t IF (pos(change[0],~'[~' + describe(~'" +  dw_1.describe( "#" + string(ll_i) +  ".Name") + ".ID~') + ~']~') > 0, RGB(255,255,0),RGB(255,0,255))~""
		ls_msg = dw_1.Modify(ls_modstring)
	END IF
NEXT

dw_1.setRedraw(true)

I saw the reference to the background.mode in the PB help but didn't realize you have to set that when you intend on modifying the background.color.

Matt




"Nature forges everything on the anvil of time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top