|
|
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Some petitions for GridCtrl
Some petitions for GridCtrl [message #27167] |
Tue, 29 June 2010 11:11  |
 |
koldo
Messages: 3435 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
|
|
|
Re: Some petitions for GridCtrl [message #27197 is a reply to message #27167] |
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 
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   |
 |
koldo
Messages: 3435 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 
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
Best regards
Iñaki
|
|
|
|
|
|
|
|
|
Re: Some petitions for GridCtrl [message #27478 is a reply to message #27463] |
Tue, 20 July 2010 00:03   |
|
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.

(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 #27623 is a reply to message #27476] |
Mon, 26 July 2010 17:42   |
 |
koldo
Messages: 3435 Registered: August 2008
|
Senior Veteran |
|
|
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 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
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Tue May 13 11:19:38 CEST 2025
Total time taken to generate the page: 0.01692 seconds
|
|
|