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
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 previous 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 );
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Inheriting from DropGrid
Next Topic: DoSum(), DoAvg(), etc... and search operations
Goto Forum:
  


Current Time: Sat Jul 05 03:42:56 CEST 2025

Total time taken to generate the page: 0.03922 seconds