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 » Retreiving data from sorted GridCtrl
Retreiving data from sorted GridCtrl [message #37103] Thu, 23 August 2012 05:09 Go to next message
nixnixnix is currently offline  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 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

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 Go to previous messageGo to next message
Sender Ghost is currently offline  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


Edit: Clarified some moments.

[Updated on: Thu, 23 August 2012 21:54]

Report message to a moderator

Re: Retreiving data from sorted GridCtrl [message #37142 is a reply to message #37106] Wed, 29 August 2012 07:58 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Ooops,my mistake. It seems there is no such a method. I'll try to provide one.
Re: Retreiving data from sorted GridCtrl [message #37279 is a reply to message #37142] Fri, 14 September 2012 09:17 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

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 #37282 is a reply to message #37279] Fri, 14 September 2012 10:45 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Daniel

As this behavior may produce problems, is there a function that "fixes" all the changes in a GridCtrl?.

I mean, the user moves the rows (Dragging()) and reorder them (Sorting()). After that, I want to handle the GridCtrl as "it is seen".

As you have told before, Get(row, col) works like this. Also GetCursorPos().y gets the real selected row (GetRowId() gets the initial row before the reorder). However Xmlize()/Jsonize() functions do not store the new reorderer GridCtrl.


Best regards
Iñaki
Re: Retreiving data from sorted GridCtrl [message #37283 is a reply to message #37282] Fri, 14 September 2012 11:01 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

koldo wrote on Fri, 14 September 2012 04:45

However Xmlize()/Jsonize() functions do not store the new reorderer GridCtrl.

Ok, now I get it Smile
Re: Retreiving data from sorted GridCtrl [message #37284 is a reply to message #37279] Fri, 14 September 2012 11:08 Go to previous messageGo to next message
Sender Ghost is currently offline  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 #37285 is a reply to message #37284] Fri, 14 September 2012 11:41 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Ok, thank you for explanations. So I have to add method for getting ctrl and make xmlize and jsonize aware of display order.
Re: Retreiving data from sorted GridCtrl [message #37299 is a reply to message #37285] Mon, 17 September 2012 18:51 Go to previous messageGo to next message
nixnixnix is currently offline  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 #37313 is a reply to message #37299] Wed, 19 September 2012 09:45 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Daniel

It is true.

It would be great if you could set a clear interface to get and set cells taking into account the real location or the visual location of the cells. And perhaps to have a way to say to GridCtrl that the visual location is the real location, for example, just before storing it. This is not always true so the programmer would have to call that function explicitely.


Best regards
Iñaki
Re: Retreiving data from sorted GridCtrl [message #37601 is a reply to message #37313] Wed, 24 October 2012 21:54 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Sorry for taking it so long but better late than never Wink
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.
Re: Retreiving data from sorted GridCtrl [message #37609 is a reply to message #37601] Thu, 25 October 2012 21:12 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Daniel

Could you add a function that moves the visual data to the real data to be used just before saving with serialize functions?.


Best regards
Iñaki
Previous Topic: DropGrid .t file
Next Topic: SetDisplay, which works for column why not for cells ??
Goto Forum:
  


Current Time: Thu Mar 28 17:34:12 CET 2024

Total time taken to generate the page: 0.01720 seconds