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: Adding column dynamically – How to make editable
GridCtrl: Adding column dynamically – How to make editable [message #23357] Tue, 13 October 2009 18:12 Go to next message
supa is currently offline  supa
Messages: 5
Registered: October 2009
Promising Member
First of all I am novice programmer. My understanding by going through the forum discussion is that:
(1)To make column editable I have to bind a column with an edit control. (2) These edit controls can not be declared in the constructor at the run time should be declared in the class.

My requirement is that I am adding columns dynamically at the run time, from the select statement. Therefore not sure what columns or editable fields would I need, and therefore can not declare them in the class.

void MyApp::QQuery()
{
Sql sql(SQL.GetSession());
String current_stmt_string;
QResultTab.Add(QResultTab1.SizePos(),t_("QResultTab1"));

QResultTab1.Add(QResultArray.SizePos(), t_("QResultArray"));
QResultArray.Reset();
QResultArray.ResizeColMode(0); // This will change created cloumn's width to use absolute mode from ratio mode.
//GridControl->
QResultArray.Appending().Removing().Editing().Accepting().Ca nceling().EditCell();
QResultArray.RejectNullRow();

current_stmt_string = "SELECT * FROM BOOK T1 LEFT JOIN BORROW_RECORD T2 ON T1.ID = T2.BOOK_ID";

if (sql.Execute(current_stmt_string)){
int colCount = sql.GetColumns(); // Craete columns dynamically in the grid
for (int i=0; i<colCount; ++i){
QResultArray.AddColumn(sql.GetColumnInfo(i).name, t_(sql.GetColumnInfo(i).name),50).Edit(??????????);
}
QResultArray.EditCell();
for(;;) {
Vector<Value> row;
if(!sql.Fetch(row)) break;
QResultArray.Add(row);
}
}
Sizeable().Zoomable();
}


My question is How can I make the grid cells/rows editable?
Re: GridCtrl: Adding column dynamically – How to make editable [message #23359 is a reply to message #23357] Tue, 13 October 2009 19:22 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
In your class, do something like:

private:
    EditString myStringEditor;


Then where you have .Edit(???), just put .Edit(myStringEditor)

Jeremy
Re: GridCtrl: Adding column dynamically – How to make editable [message #23361 is a reply to message #23357] Tue, 13 October 2009 19:55 Go to previous messageGo to next message
supa is currently offline  supa
Messages: 5
Registered: October 2009
Promising Member
Jeremy, Thanks you very much for quick response.
I do not know why, but this solution did not work. Still not be able to edit cell/row. May be I am doing some thing else wrong.

In the mean time I experimented by putting “.Ctrls<EditString>()” at the place of Edit ( I got clue from the ArrayCtrl post). It created editable cells, but the problem is that the grid (all column and rows) gets painted without data in it, and when I move cursor into the each row, data appears there, and of course that data is editable.

Q1: What else is possible in Jeremy’s solution?
Q2: Is my experimental solution is possible solution.
Q3. If answer to Q2 is Yes, then how can I resolve data painting issue.
Re: GridCtrl: Adding column dynamically – How to make editable [message #23362 is a reply to message #23357] Tue, 13 October 2009 20:26 Go to previous messageGo to next message
supa is currently offline  supa
Messages: 5
Registered: October 2009
Promising Member
Note: Another issue I found, with my experimental solution mentioned above, is that editing is possible at the cell level only. I can not select a row in the grid.
Re: GridCtrl: Adding column dynamically – How to make editable [message #23363 is a reply to message #23362] Tue, 13 October 2009 20:40 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

supa, there is a number of examples. Please find one for GridCtrl. There is also Help (called by F1), it may give you some examples on GridCtrl too.
Re: GridCtrl: Adding column dynamically – How to make editable [message #23364 is a reply to message #23361] Tue, 13 October 2009 20:41 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
I'm sorry, if that did not fix the problem, I am unsure of whatelse may be wrong. I am new to U++ as well but I do have many GridCtrl's that are directly editable using the method I described.

Sorry I couldn't be of more help!

Jeremy
Re: GridCtrl: Adding column dynamically – How to make editable [message #23367 is a reply to message #23364] Tue, 13 October 2009 21:57 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I have included for the convenience of full original code.
Quote:


void MyApp::QQuery()
{
	Sql sql ( SQL.GetSession() );
	String current_stmt_string;
	QResultTab.Add ( QResultTab1.SizePos(), t_ ( "QResultTab1" ) );

	QResultTab1.Add ( QResultArray.SizePos(), t_ ( "QResultArray" ) );
	QResultArray.Reset();
	QResultArray.ResizeColMode ( 0 ); // This will change created cloumn's width to use absolute mode from ratio mode.
//GridControl->
	QResultArray.Appending().Removing().Editing().Accepting().Ca nceling().EditCell();
	QResultArray.RejectNullRow();

	current_stmt_string = "SELECT * FROM BOOK T1 LEFT JOIN BORROW_RECORD T2 ON T1.ID = T2.BOOK_ID";

	if ( sql.Execute ( current_stmt_string ) )
	{
		int colCount = sql.GetColumns(); // Craete columns dynamically in the grid

		for ( int i = 0; i < colCount; ++i )
		{
			QResultArray.AddColumn ( sql.GetColumnInfo ( i ).name, t_ ( sql.GetColumnInfo ( i ).name ), 50 ).Edit ( ? ? ? ? ? ? ? ? ? ? );
		}

		QResultArray.EditCell();

		for ( ;; )
		{
			Vector<Value> row;

			if ( !sql.Fetch ( row ) )
				break;

			QResultArray.Add ( row );
		}
	}

	Sizeable().Zoomable();
}


Well, firstly. In this piece of code - the program reads the line, not columns.
Quote:


		for ( ;; )
		{
			Vector<Value> row;

			if ( !sql.Fetch ( row ) )
				break;

			QResultArray.Add ( row );
		}
	}

	Sizeable().Zoomable();
}



In my humble opinion there is a lack of understanding of containers U++.

I recommend 1 times per day to sit down and reread the article http://www.ultimatepp.org/srcdoc$Core$Tutorial$en-us.html to a full understanding. There are not very clear written for beginners, but with no understanding of the containers will not be able to write such a program using containers.

For example, in the last quoted piece should be
Vector<Vector<Value> >

instead of
Vector<Value>


And if we talk about editing, then this definition should be in the class definition, but not in the local context. And then you can insert a variable EditString in the definition of the vector.

If the field is of indefinite type and want to use the type of Value, it is better to use the type "EditField", but not the type "EditString".

Then, while reading the lines and the recognition of the fields you want included in the definition of the class definition line for editing:
Vector<EditField> editline



When you add a column should write something like:
EditField& f = editline.Add();
QResultArray.AddColumn ( sql.GetColumnInfo ( i ).name, t_ ( sql.GetColumnInfo ( i ).name ), 50 ).Edit ( f );


or, in short the same:

QResultArray.AddColumn ( sql.GetColumnInfo ( i ).name, t_ ( sql.GetColumnInfo ( i ).name ), 50 ).Edit ( editline.Add() );




SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: GridCtrl: Adding column dynamically – How to make editable [message #23368 is a reply to message #23367] Tue, 13 October 2009 22:53 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Another comment, just noticed that you are using a macro
t_()
at runtime. In my opinion this is a macro definition for the compiler, and only works at compile time, and during the work can not be used (although could be wrong).


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: GridCtrl: Adding column dynamically – How to make editable [message #23369 is a reply to message #23357] Wed, 14 October 2009 00:03 Go to previous messageGo to next message
supa is currently offline  supa
Messages: 5
Registered: October 2009
Promising Member
Thank you sergeynikitin, and Mindtraveller. I feel privileged to get response from the senior members like you.
Sergey, I know I need to do lot of learning, and I’ll keep on working on that. I am an old C programmer who is returning to programming after more than a decade. So a lot to catch up, and for that I value each comment and information on this forum. During my last couple of weeks of starting into U++ (I chose U++ to restart programming because of its apparent simplicity), most of the time I am spending is on going through documentation and valuable forums and examples.

On Sergey’s solution to use EditField like in Vector<EditField> editline, my compiler is giving error, complaining about “cannot access private member declared in class” in EditCtrl.h

Any suggestion?

Thanks.
Re: GridCtrl: Adding column dynamically – How to make editable [message #23370 is a reply to message #23369] Wed, 14 October 2009 03:55 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I did not test my solution. It must be near.

By the way, I'll try to solve a similar problem, if something will come, be sure to share my solution.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Wed, 14 October 2009 23:20]

Report message to a moderator

Re: GridCtrl: Adding column dynamically – How to make editable [message #23374 is a reply to message #23370] Wed, 14 October 2009 19:23 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Vector should be replaced by Array.

class definition:
class DynGridTest : public WithDynGridTestLayout<TopWindow> {
public:
	typedef DynGridTest CLASSNAME;
	DynGridTest();
	void Prepare();
	Array<EditString> vs; // <-- Must be in class definition
};


main.cpp:
DynGridTest::DynGridTest()
{
	CtrlLayout(*this, "Grid Dynamic Column Add Test");

}
void DynGridTest::Prepare() {
	vs.Clear();
	for(int i = 0; i < 10; i++) {
		grd.AddColumn("col"+AsString(i)).Editable(true).Edit(vs.Add());
	}
	for(int i = 0; i < 10; i++) {
		grd.Add();
		for(int j = 0; j < 10; j++) {
			grd(j) = "x="+AsString(j)+"; y="+AsString(i);
		}
	}
	grd.SetToolBar();
}

GUI_APP_MAIN
{
	DynGridTest app;
	app.Prepare();
	app.Run();
}


This example works fine.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: GridCtrl: Adding column dynamically – How to make editable [message #23375 is a reply to message #23357] Wed, 14 October 2009 20:46 Go to previous messageGo to next message
supa is currently offline  supa
Messages: 5
Registered: October 2009
Promising Member
Thank you, thank you Sergey.
It worked for me. The only thing I observed (and this is my interpretation may not be correct) is that when we do the fetch using Vector<Value>, the value is RichValue, while the edit field we defined via Array<EditString> is String. In that case, the fetch worked fine, but while editing it gave conversion error.
So at fetch I converted to String and it worked fine.
It was great help and learning to me.
Re: GridCtrl: Adding column dynamically – How to make editable [message #23377 is a reply to message #23375] Wed, 14 October 2009 23:16 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

A more comprehensive example. The last but one column - type of date. The last column - integer.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Previous Topic: Inheriting from DropGrid
Next Topic: DoSum(), DoAvg(), etc... and search operations
Goto Forum:
  


Current Time: Thu Mar 28 19:46:09 CET 2024

Total time taken to generate the page: 0.01528 seconds