Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Retreiving data from sorted GridCtrl
Retreiving data from sorted GridCtrl [message #37103] |
Thu, 23 August 2012 05:09  |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
This must have been asked before so I apologise in advance but I couldn't find it when searching.
When I sort a GridCtrl, I find I can still retrieve data by the original row number for the Ctrls that I have added myself as, of course, they can be accessed by their original index in my Array of Ctrl objects. However, I do not see how to access data that is just sitting in the GridCtrl itself and that is not longer in its original row due to sorting. I know there must be a way to do this already but how?
Nick
|
|
|
Re: Retreiving data from sorted GridCtrl [message #37105 is a reply to message #37103] |
Thu, 23 August 2012 10:09   |
|
nixnixnix wrote on Wed, 22 August 2012 23:09 | This must have been asked before so I apologise in advance but I couldn't find it when searching.
When I sort a GridCtrl, I find I can still retrieve data by the original row number for the Ctrls that I have added myself as, of course, they can be accessed by their original index in my Array of Ctrl objects. However, I do not see how to access data that is just sitting in the GridCtrl itself and that is not longer in its original row due to sorting. I know there must be a way to do this already but how?
Nick
|
Use:
Item& GetItem(int n, int m)
n is a row number related to sort order used to paint the grid.
[Updated on: Thu, 23 August 2012 11:19] Report message to a moderator
|
|
|
Re: Retreiving data from sorted GridCtrl [message #37106 is a reply to message #37103] |
Thu, 23 August 2012 19:34   |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
Hello, Nick, Uno.
unodgs wrote on Thu, 23 August 2012 10:09 | Use:
Item& GetItem(int n, int m)
n is a row number related to sort order used to paint the grid.
|
The GridCtrl::Item& GetItem(int n, int m) method of GridCtrl is private. Did you mean GridCtrl::Item& GridCtrl::GetCell(int n, int m) method?
nixnixnix wrote on Wed, 22 August 2012 23:09 | When I sort a GridCtrl, I find I can still retrieve data by the original row number for the Ctrls that I have added myself as, of course, they can be accessed by their original index in my Array of Ctrl objects. However, I do not see how to access data that is just sitting in the GridCtrl itself and that is not longer in its original row due to sorting. I know there must be a way to do this already but how?
|
In case of manually created Ctrls inside of Array and assigned to GridCtrl through GridCtrl::SetCtrl method, there is also possible to use int GridCtrl::GetRowId() const or int GridCtrl::GetRowId(int n) const public methods to get "original index" for selected or appropriate row. Then you could use it for Array of unsorted Ctrl objects.
There are also Ctrl *GridCtrl::GetCtrl(int c) and Ctrl *GridCtrl::GetCtrl(int r, int c) methods to access Ctrl object through pointer:
Toggle Spoiler
#include <GridCtrl/GridCtrl.h>
using namespace Upp;
void CreateEditString(One<Ctrl>& ctrl) {
EditString& edit = ctrl.Create<EditString>();
edit.NoWantFocus();
}
class App : public TopWindow {
public:
typedef App CLASSNAME;
App();
GridCtrl list;
StaticText text;
void OnCursor();
};
App::App()
{
Title("GridCtrl sorting example");
Sizeable().Zoomable();
const Size sz(320, 240);
SetMinSize(sz); SetRect(sz);
list.Chameleon().Sorting();
list.AddColumn("Index").Ctrls(CreateEditString);
list.WhenCursor = THISBACK(OnCursor);
text.SetFrame(ThinOutsetFrame());
text.SetImage(CtrlImg::smallright(), 4);
list.Ready(false);
for (int i = 0; i <= 10; ++i) {
list.Add(AsString(i));
}
list.Ready(true);
OnCursor();
Add(list.VSizePosZ(4, 27).HSizePosZ(4, 4));
Add(text.BottomPosZ(4, 19).HSizePosZ(4, 4));
}
void App::OnCursor()
{
const int cursor = list.GetCursor(), id = list.GetRowId();
#if 1
EditString *ctrl = reinterpret_cast<EditString *>(list.GetCtrl(id, 0));
if (ctrl)
text.SetText(Format("cursor = %d; id = %d; Value = \"%s\"", cursor, id, ctrl->GetData()));
#else // But also enough to use GridCtrl::Get method in this case
text.SetText(Format("cursor = %d; id = %d; Value = \"%s\"", cursor, id, list.Get(cursor, 0)));
#endif
}
GUI_APP_MAIN
{
App app;
app.Run();
}
Edit: Clarified some moments.
[Updated on: Thu, 23 August 2012 21:54] Report message to a moderator
|
|
|
|
Re: Retreiving data from sorted GridCtrl [message #37279 is a reply to message #37142] |
Fri, 14 September 2012 09:17   |
|
I searched through the grid api once again and Get(int r, int c) should return value from row that reflects display order.
If it's not working for you please paste your code here so I was sure we're thinking about the same problem.
|
|
|
|
|
Re: Retreiving data from sorted GridCtrl [message #37284 is a reply to message #37279] |
Fri, 14 September 2012 11:08   |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
unodgs wrote on Fri, 14 September 2012 09:17 | I searched through the grid api once again and Get(int r, int c) should return value from row that reflects display order.
If it's not working for you please paste your code here so I was sure we're thinking about the same problem.
|
If you asked to my reply, then in my example I already showed the case with Get method for selected row:
void App::OnCursor()
{
const int cursor = list.GetCursor(), id = list.GetRowId();
#if 0
EditString *ctrl = reinterpret_cast<EditString *>(list.GetCtrl(id, 0));
if (ctrl)
text.SetText(Format("cursor = %d; id = %d; Value = \"%s\"", cursor, id, ctrl->GetData()));
#else // But also enough to use GridCtrl::Get method in this case
text.SetText(Format("cursor = %d; id = %d; Value = \"%s\"", cursor, id, list.Get(cursor, 0)));
#endif
}
But the row id needed in the case of GetCtrl method:
void App::OnCursor()
{
const int cursor = list.GetCursor(), id = list.GetRowId();
#if 1
EditString *ctrl = reinterpret_cast<EditString *>(list.GetCtrl(id, 0));
if (ctrl)
text.SetText(Format("cursor = %d; id = %d; Value = \"%s\"", cursor, id, ctrl->GetData()));
#else // But also enough to use GridCtrl::Get method in this case
text.SetText(Format("cursor = %d; id = %d; Value = \"%s\"", cursor, id, list.Get(cursor, 0)));
#endif
}
Considering the same variable names inside of Value GridCtrl::Get(int r, int c) const and Ctrl * GridCtrl::GetCtrl(int r, int c) methods (as row and column), the GetCtrl method should work as Get method with current selected cursor (even in case of sorting), but it doesn't (and require row id instead), currently.
The GridCtrl::Item& GridCtrl::GetCell(int n, int m) have no methods to return Ctrl * and useful to manage Display(s), for example (in case of unimplemented void GridCtrl::SetDisplay(int r, int c, GridDisplay& gd) method).
[Updated on: Fri, 14 September 2012 11:13] Report message to a moderator
|
|
|
|
Re: Retreiving data from sorted GridCtrl [message #37299 is a reply to message #37285] |
Mon, 17 September 2012 18:51   |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Hi Daniel,
From this thread it is not apparent to me what the situation is now.
So far as I can tell, Get(int r,int c) gets the value at the currently displayed row and column. Presumably, Set(int r,int c,Value v) sets the value at the currently displayed row and column.
What I would like is if you could add a SetUnsorted(int r,int c,Value v) and GetUnsorted(int r,int c) or whatever names they should go by. These functions would access the data by their original row and column.
Thanks,
Nick
|
|
|
|
Re: Retreiving data from sorted GridCtrl [message #37601 is a reply to message #37313] |
Wed, 24 October 2012 21:54   |
|
Sorry for taking it so long but better late than never 
GetCtrl(c) and GetCtrl(r, c) should refer to the same column and row as in Get(c) and GetCtrl(r, c) respectively.
Instead of GetUnsorted and SetUnsorted I added GetRaw(r, c) and SetRaw(r, c, const Value&). In both cases r and c address internal items matrix directly. Also remember that SetRaw only sets the value. It doesn't do anything else so user is responsible for refreshing modified row or particular cell. It also doesn't trigger any grid callbacks.
I hope that those changes satisfy you. If not or there is still something wrong please let me know.
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 11:20:45 CEST 2025
Total time taken to generate the page: 0.01202 seconds
|