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 next message
koldo is currently offline  koldo
Messages: 3040
Registered: August 2008
Ultimate Member
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
Re: Some petitions for GridCtrl [message #27197 is a reply to message #27167] Thu, 01 July 2010 14:35 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1355
Registered: November 2005
Location: Poland
Senior Contributor

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
Quote:


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
Quote:


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
Quote:


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



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


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.

Re: Some petitions for GridCtrl [message #27232 is a reply to message #27197] Tue, 06 July 2010 20:37 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3040
Registered: August 2008
Ultimate Member
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
Quote:


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
Quote:


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
Quote:


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



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


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
Iñaki
Add a control into the GridCtrl [message #27414 is a reply to message #27167] Fri, 16 July 2010 09:37 Go to previous messageGo to next message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
Hy,

I'd like to add a question about Grid control like this
index.php?t=getfile&id=2658&private=0

My problme is about adding Ctrl like droplist into a cell (See attached). Here is the code i used without success (no error in compilation but the exe doesn't run!!)


grid.AddColumn("opration", w2);
grid.AddColumn("Date", w3);
grid.AddColumn("Montant", w4);

grid.AddRow(1);

grid.GetCtrl(0,2)->Add(dropDate);

Thank you for your responses
  • Attachment: GRID.jpg
    (Size: 22.61KB, Downloaded 609 times)
Re: Add a control into the GridCtrl [message #27456 is a reply to message #27414] Sun, 18 July 2010 23:12 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1355
Registered: November 2005
Location: Poland
Senior Contributor

You can't assign control to particular cell. You can assign it to the column like this:
DropDate date;
GridCtrl grid;

grid.AddColumn("Date").Edit(date);
Re: Some petitions for GridCtrl [message #27457 is a reply to message #27232] Mon, 19 July 2010 00:51 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1355
Registered: November 2005
Location: Poland
Senior Contributor

Please check latest svn code. It all should be there. Please give me a sign if something isn't working as you expected or you found a bug (I haven't tested this code too much).
Re: Some petitions for GridCtrl [message #27463 is a reply to message #27457] Mon, 19 July 2010 09:26 Go to previous messageGo to next message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
Thank you for your response,
Quote:

You can assign it to the column like this:
grid.AddColumn("Date").Edit(date);


I need it on a line like a header where i apply filter (by date, an autocompletion into a editString, sort by code,...).

I tried to use an easy way by superposing my controls juste under the header and it have another bug: it does not refresh drawing as well when i scroll vertically.
index.php?t=getfile&id=2665&private=0
(Sorry for my english, i 'am french speaker!!)

  • Attachment: refresh.gif
    (Size: 8.84KB, Downloaded 626 times)

[Updated on: Mon, 19 July 2010 09:27]

Report message to a moderator

Re: Some petitions for GridCtrl [message #27464 is a reply to message #27457] Mon, 19 July 2010 09:28 Go to previous messageGo to next message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
I use the last release 2467 (windows version of ultimate++)
Re: Some petitions for GridCtrl [message #27476 is a reply to message #27457] Mon, 19 July 2010 22:53 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3040
Registered: August 2008
Ultimate Member
unodgs wrote on Mon, 19 July 2010 00:51

Please check latest svn code. It all should be there. Please give me a sign if something isn't working as you expected or you found a bug (I haven't tested this code too much).

Hello Daniel

Thank you. I will test it.


Best regards
Iñaki
Re: Some petitions for GridCtrl [message #27478 is a reply to message #27463] Tue, 20 July 2010 00:03 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1355
Registered: November 2005
Location: Poland
Senior Contributor

ratah wrote on Mon, 19 July 2010 03:26

Thank you for your response,
Quote:

You can assign it to the column like this:
grid.AddColumn("Date").Edit(date);


I need it on a line like a header where i apply filter (by date, an autocompletion into a editString, sort by code,...).

I tried to use an easy way by superposing my controls juste under the header and it have another bug: it does not refresh drawing as well when i scroll vertically.
index.php?t=getfile&id=2665&private=0
(Sorry for my english, i 'am french speaker!!)



Could you attach your code if it's not a problem?
Re: Some petitions for GridCtrl [message #27505 is a reply to message #27478] Wed, 21 July 2010 14:00 Go to previous messageGo to next message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
my code project has been sent to you in private message!
Thank you
Re: Some petitions for GridCtrl [message #27623 is a reply to message #27476] Mon, 26 July 2010 17:42 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3040
Registered: August 2008
Ultimate Member
koldo wrote on Mon, 19 July 2010 22:53

unodgs wrote on Mon, 19 July 2010 00:51

Please check latest svn code. It all should be there. Please give me a sign if something isn't working as you expected or you found a bug (I haven't tested this code too much).

Hello Daniel

Thank you. I will test it.

Hello Daniel

I have tested the functions and for me are ok, but some details in ReadCol() that I think are not natural, as now:
- the first grid column is the #1 instead of the 0#
- the row 0# is the header so the first data row is the row #1
- end_row is copied or not to the Vector?

Please post in the Forum as usual Smile if you change something as this affects to production code.


Best regards
Iñaki

[Updated on: Mon, 26 July 2010 17:44]

Report message to a moderator

Re: Some petitions for GridCtrl [message #27670 is a reply to message #27623] Thu, 29 July 2010 00:01 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1355
Registered: November 2005
Location: Poland
Senior Contributor

koldo wrote on Mon, 26 July 2010 11:42

- the first grid column is the #1 instead of the 0#
- the row 0# is the header so the first data row is the row #1


Should be fixed now.
Quote:


- end_row is copied or not to the Vector?


yes, it's copied

[Updated on: Thu, 29 July 2010 07:52]

Report message to a moderator

Re: Some petitions for GridCtrl [message #27673 is a reply to message #27670] Thu, 29 July 2010 08:47 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3040
Registered: August 2008
Ultimate Member
Thank you !

Tested ok!


Best regards
Iñaki

[Updated on: Thu, 29 July 2010 10:33]

Report message to a moderator

Re: Some petitions for GridCtrl [message #28896 is a reply to message #27167] Fri, 24 September 2010 13:21 Go to previous messageGo to next message
sevenjay is currently offline  sevenjay
Messages: 30
Registered: October 2008
Location: Taiwan
Member
Hi,
I have the other petition.
It's like koldo's first one.
Giving a column Id, it returns its column index.
It's convenient for me because my column names sometimes change.
I write this:
int GridCtrl::FindCol(const Id& id) const
{
    for(int i = fixed_cols; i < total_cols; i++)
        if(aliases.GetKey(i) == id)
            return i - fixed_cols;
    return -1;
}
hope this useful
Re: Some petitions for GridCtrl [message #28912 is a reply to message #28896] Sun, 26 September 2010 04:18 Go to previous messageGo to next message
sevenjay is currently offline  sevenjay
Messages: 30
Registered: October 2008
Location: Taiwan
Member
more one, i need to record the width of each column.
Find the width by Id:
int GridCtrl::FindColWidth(const Id& id)
{
    for(int i = fixed_cols; i < total_cols; i++)
        if(aliases.GetKey(i) == id)
            return hitems[i].Width();

    return -1;
}

And there is a little bug for column Hidden().
when column Hidden(false) will be hidden.
Modify in GridBase.cpp:
GridCtrl::ItemRect& GridCtrl::ItemRect::Hidden(bool b)
{
    hidden = b;
    if(hidden) size = 0;//modify this to avoid alway hidden
    return *this;
}

BTW, GridCtrl is a very great control.
Thank you all.
Re: Some petitions for GridCtrl [message #28927 is a reply to message #28912] Mon, 27 September 2010 19:06 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1355
Registered: November 2005
Location: Poland
Senior Contributor

Thanks! Hidden fixed, FindCol added (FindColWidth is too specific)
Re: Some petitions for GridCtrl [message #28983 is a reply to message #28927] Thu, 30 September 2010 10:52 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3040
Registered: August 2008
Ultimate Member
Hello unodgs

I have found that you have included CopyColumnNames() function to copy column names to the Clipboard (I have discovered it when I was going to implement it by myself Wink).

Have you included more things?


Best regards
Iñaki
Re: Some petitions for GridCtrl [message #30000 is a reply to message #27167] Thu, 02 December 2010 13:51 Go to previous message
AnnabelleR is currently offline  AnnabelleR
Messages: 4
Registered: November 2010
Location: Usa
Junior Member
I tried it and it is working ok.
Thanks for the information. Smile
Previous Topic: GridCtrl changed add row behavior
Next Topic: UI virtualization
Goto Forum:
  


Current Time: Fri Dec 06 09:53:48 CET 2019

Total time taken to generate the page: 0.01399 seconds