Status & Roadmap
Authors & License
Funding Ultimate++
Search on this site
Search in forums

SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Some petitions for GridCtrl
Re: Some petitions for GridCtrl [message #27232 is a reply to message #27197] Tue, 06 July 2010 20:37 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3195
Registered: August 2008
Senior Veteran
unodgs wrote on Thu, 01 July 2010 14:35

koldo wrote on Tue, 29 June 2010 05:11

Hello Uno

I have some petitions to be implemented in GridCtrl.
If they are already implemented please tell me how to do it:

1. A kind of FindColumn function
Giving a column name, it returns its column index.
It could be like this:

int GridCtrl_FindColumn(GridCtrl &grid, String &colName) {
	for (int i = 0; i < grid.GetColumnCount(); ++i) {
		if (grid.GetColumnName(i) == colName)
			return i;
	return -1;

There is only FindCol(int id). I've never needed searching by column name that's why such method doesn't exist Smile

2. Copy to Clipboard including column names row
At least an option to let this copy to clipboard behavior.
This way when copying a grid to an spreadsheet the column names would appear.

I will modify SetClipboard method to do that

3. A kind of ReadCol function
A function to read a column (or part of it)
It could be like this:

Vector<Value> ReadCol(GridCtrl& grid, int col, int begin, int end) 
	if (begin < 0 || end >= grid.GetRowCount() || col < 0 || col >= grid.GetColumnCount())
		throw Exc(t_("Wrong param. in ReadCol"));
	Vector<Value> v;
	for(int i = begin; i <= end; i++)
		v.Add(grid(i, col));
	return v;

There's only ReadRow. I agree having ReadCol would be useful too

4. A kind of GetGridData/SetGridData functions
Some functions to set GridCtrl data to a Vector<Vector<Value> > and the opposite.
They could be like this:

Vector<Vector<Value> > GetGridData(GridCtrl& grid) {
	Vector<Vector<Value> > data;
	for (int row = 0; row < grid.GetRowCount()+1; ++row) 
	return data;
void SetGridData(GridCtrl& grid, Vector<Vector<Value> > &data) {
	if (!data.IsEmpty()) { 
		int nrow = data.GetCount();
		int ncol = data[0].GetCount();
		for (int col = 0; col < data[0].GetCount(); ++col) 
		for (int row = 0; row < grid.GetRowCount(); ++row) 
			for (int col = 0; col < grid.GetColumnCount(); ++col) 
				grid(row, col) = data[row+1][col];

I'm not sure if these methods should be part of grid api. I'll think about that.

5. Xmlize
A simple implementation could be like this
template <> void Xmlize(XmlIO xml, GridCtrl& r) {
	Vector<Vector<Value> > data;
	if(xml.IsLoading()) {
		xml("data", data);
		SetGridData(r, data);
	} else {
		data = GetGridData(r);
		xml("data", data);

Yes, easy loading/saving from/to xml would be nice.

I'll try to add most of requested functionality in a few days.

Thank you Smile

Best regards
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
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: GridCtrl changed add row behavior
Next Topic: UI virtualization
Goto Forum:

Current Time: Mon Sep 21 17:45:14 CEST 2020

Total time taken to generate the page: 0.01479 seconds