Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Coloring a row in a SqlArray
Coloring a row in a SqlArray [message #50154] Thu, 09 August 2018 14:34 Go to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi there,
is there a way to set the color of a row of a SqlArray basing on a value of the related record in the database?

I have this SqlArray and - according on the value of a certain field that is not shown on screen - the line itself should be green or not colored.

So far, I have set a callback to the post query event: mySqlArray.WhenPostQuery = THISBACK(ColorLines).

The ColorLines() method is as follows:

void MyApp::ColorLines()
{
	for(int i = 0;i<mySqlArray.GetCount();i++) {
		mySqlArray.SetCursor(i);
		if(DB_data.IsAvailable(mySqlArray.GetKey()))
			JobList.SetLineColor(i, LtGreen());
	}
}


The DB_data.IsAvailable() method, checks the value of the field Available for the record: if the value is Y (yes) the method returns true, and the row will be colored in green. This approach works, indeed, but it seems to me really inefficient: to fill in the table I have just issued a select statement to the table, now I am issuing an additional select for each row of the table. Is there a way for me to set the color at the same tome when filling the table?

As a side question: to get the *value* of the primary key there is the very convenient method GetKey(). The problem is that it returns "the value of the current row's primary key". To go through all the rows, I have to use SetCursursor(i) in the for loop to make the i-th row the current one. Does it exist a method like GetKey(int i) that returns the value of the key of the i-th row?

Regards,
Gio

[Updated on: Thu, 09 August 2018 14:37]

Report message to a moderator

Re: Coloring a row in a SqlArray [message #50186 is a reply to message #50154] Mon, 20 August 2018 08:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Giorgio wrote on Thu, 09 August 2018 14:34

The DB_data.IsAvailable() method, checks the value of the field Available for the record: if the value is Y (yes) the method returns true, and the row will be colored in green. This approach works, indeed, but it seems to me really inefficient: to fill in the table I have just issued a select statement to the table, now I am issuing an additional select for each row of the table. Is there a way for me to set the color at the same tome when filling the table?


Unfortunate... really unfortunate.

Either you can consider to fill the table NOT USING Query and set line color as you add rows. In that case, it is possible that you will rather want to use ArrayCtrl instead.

Or you can AddIndex to store the value that you wish to use for the color, then either setup Display based on the index or just test this index in ColorLines.

Depends on what is in "IsAvailable"...

Quote:

As a side question: to get the *value* of the primary key there is the very convenient method GetKey(). The problem is that it returns "the value of the current row's primary key". To go through all the rows, I have to use SetCursursor(i) in the for loop to make the i-th row the current one. Does it exist a method like GetKey(int i) that returns the value of the key of the i-th row?


Yeah, that is not right approach. Just use .Get(i, 0) - primary key is by definition always the first index.

Mirek
Re: Coloring a row in a SqlArray [message #50210 is a reply to message #50186] Mon, 27 August 2018 13:16 Go to previous message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
mirek wrote on Mon, 20 August 2018 08:43

Or you can AddIndex to store the value that you wish to use for the color, then either setup Display based on the index or just test this index in ColorLines.


Hi Mirek,
thanks for the answer, the AddIndex() method worked as a charm.

Before you answered, to fix this issue, I added a "hidden" column (a column with a width of -1) containing the value used to color the lines. That worked, but the user was able to see that value if he manually changed the column width. I searched for a method to make the column really hidden, but I did not find it (there is a Hide() method, but is for Ctrl). So, just to get to know better UPP, does such method exist?

Regards,
Gio

[Updated on: Mon, 27 August 2018 13:16]

Report message to a moderator

Previous Topic: small issue in CompDir Example
Next Topic: Adding a records through a SqlArray with duplicated columns
Goto Forum:
  


Current Time: Fri Apr 19 15:45:47 CEST 2024

Total time taken to generate the page: 0.06943 seconds