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 » Some petitions for GridCtrl
Some petitions for GridCtrl [message #27167] Tue, 29 June 2010 11:11 Go to previous message
koldo is currently offline  koldo
Messages: 3195
Registered: August 2008
Senior Veteran
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;
}


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.

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;
}


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) 
		data.Add(grid.ReadRow(row));
	
	return data;
}
void SetGridData(GridCtrl& grid, Vector<Vector<Value> > &data) {
	grid.Clear(true);
	if (!data.IsEmpty()) { 
		int nrow = data.GetCount();
		int ncol = data[0].GetCount();
		for (int col = 0; col < data[0].GetCount(); ++col) 
			grid.AddColumn(data[0][col]);
		grid.SetRowCount(data.GetCount()-1);
		for (int row = 0; row < grid.GetRowCount(); ++row) 
			for (int col = 0; col < grid.GetColumnCount(); ++col) 
				grid(row, col) = data[row+1][col];
	}
}


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);
	}
}


Best regards
IƱaki
 
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 18:11:46 CEST 2020

Total time taken to generate the page: 0.02165 seconds