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 » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » GridCtrl and background color of a row
GridCtrl and background color of a row [message #41918] Wed, 05 February 2014 19:09 Go to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I am fighting with the GridCtrl. This code:

class RowColor : public GridDisplay
{ public:
  virtual void Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style,
				           Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe);	
};

void RowColor::Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style, Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe)
{   if (AsString(val)=="0") {
     //parent->GetRow().Bg(LtRed);
     GridDisplay::Paint(w, x, y, cx, cy, val, style, fg, LtRed(), fnt, found, fs, fe);
   }
   if (AsString(val)=="") {
     //parent->GetRow().Bg(Yellow);
     GridDisplay::Paint(w, x, y, cx, cy, val, style, fg, Yellow(), fnt, found, fs, fe);
   }  
}

and

grid.AddColumn("Status", t_("Status"), 4).Ctrls(Avail3bis).Default(true).SetDisplay(Single<RowColor >());

permit me to change the background color of a column depending a three status button and it works:

index.php?t=getfile&id=4426&private=0

I would like to extend the red/yellow color to the WHOLE row. Unfortunately I can't get the row correspondent to the right column.
Any idea?

Thanks,
Luigi
Re: GridCtrl and background color of a row [message #41931 is a reply to message #41918] Fri, 07 February 2014 14:56 Go to previous message
deep is currently offline  deep
Messages: 263
Registered: July 2011
Location: Bangalore
Experienced Member
Hi

This is modified Grid01 from tutorial.
WhenCtrlsAction callback can be changed as required.

#include <CtrlLib/CtrlLib.h>
#include <GridCtrl/GridCtrl.h>

using namespace Upp;

struct App : TopWindow {
	typedef App CLASSNAME;

	GridCtrl grid;
	EditString name;
	EditInt age;
	Option opt1;

	App() {
		Sizeable().Zoomable();

		Add ( grid.SizePos() );

		grid.AddColumn ( "Name" ).Edit ( name );
		grid.AddColumn ( "Age" ).Edit ( age );

		grid.AddColumn ( "Status", t_ ( "Status" ), 4 ).Ctrls<Option>();

		grid.Add ( "Ann", 21 )
		.Add ( "Jack", 34 )
		.Add ( "David", 15 );
		grid.Add ( "Ann", 21 )
		.Add ( "Jack", 34 )
		.Add ( "David", 15 );
		grid.Add ( "Ann", 21 )
		.Add ( "Jack", 34 )
		.Add ( "David", 15 );
		grid.Add ( "Ann", 21 )
		.Add ( "Jack", 34 )
		.Add ( "David", 15 );

		grid.Set ( 5, 0, "Daniel" );
		grid.SetFixed ( 0, 1, "Age of person" );

		grid.Indicator();
		grid.WhenLeftDouble = THISBACK ( ShowInfo );

		grid.WhenCtrlsAction = THISBACK ( SetColor );  // call back for control change

		grid.ColorRows();
		grid.EditCell();
		grid.EnterLikeTab();
		grid.GoBegin();

	}


	void ShowInfo() {
		PromptOK ( Format ( "%s is %d years old", grid ( 0 ), grid ( 1 ) ) );
	}

	void SetColor() {
		int row = grid.GetRowId();
		if ( grid.Get ( row, 2 ) == 1 ) {  // check if opt is set
			grid.GetRow ( row ).Bg ( LtGreen() );
		}
		else {
			grid.GetRow ( row ).Bg ( Yellow() );
		}

	}
};

GUI_APP_MAIN {
	App().Run();
}



Warm Regards

Deepak

[Updated on: Sat, 08 February 2014 13:18]

Report message to a moderator

Previous Topic: AddColumn(0, ...) crashes
Next Topic: Icon + text inside ArrayCtrl cell
Goto Forum:
  


Current Time: Thu Mar 28 21:04:54 CET 2024

Total time taken to generate the page: 0.01630 seconds