|
|
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  |
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 #23367 is a reply to message #23364] |
Tue, 13 October 2009 21:57   |
|
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
instead of
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 #23374 is a reply to message #23370] |
Wed, 14 October 2009 19:23   |
|
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 );
}
|
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 20:33:59 CEST 2025
Total time taken to generate the page: 0.01355 seconds
|
|
|