Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Retreiving data from sorted GridCtrl
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
|
|
|
|
|
Retreiving data from sorted GridCtrl
|
|
|
Re: Retreiving data from sorted GridCtrl
By: unodgs on Thu, 23 August 2012 10:09
|
|
|
Re: Retreiving data from sorted GridCtrl
|
|
|
Re: Retreiving data from sorted GridCtrl
By: unodgs on Wed, 29 August 2012 07:58
|
|
|
Re: Retreiving data from sorted GridCtrl
By: unodgs on Fri, 14 September 2012 09:17
|
|
|
Re: Retreiving data from sorted GridCtrl
By: koldo on Fri, 14 September 2012 10:45
|
|
|
Re: Retreiving data from sorted GridCtrl
By: unodgs on Fri, 14 September 2012 11:01
|
|
|
Re: Retreiving data from sorted GridCtrl
|
|
|
Re: Retreiving data from sorted GridCtrl
By: unodgs on Fri, 14 September 2012 11:41
|
|
|
Re: Retreiving data from sorted GridCtrl
By: nixnixnix on Mon, 17 September 2012 18:51
|
|
|
Re: Retreiving data from sorted GridCtrl
By: koldo on Wed, 19 September 2012 09:45
|
|
|
Re: Retreiving data from sorted GridCtrl
By: unodgs on Wed, 24 October 2012 21:54
|
|
|
Re: Retreiving data from sorted GridCtrl
By: koldo on Thu, 25 October 2012 21:12
|
Goto Forum:
Current Time: Thu May 09 22:35:26 CEST 2024
Total time taken to generate the page: 0.02415 seconds
|