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 » Two "basic" operations on GridCtrl
Two "basic" operations on GridCtrl [message #21019] Sun, 26 April 2009 18:27 Go to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
Hi all,

I would like to change, during runtime, the text of the columns in the header of the GridCtrl. Is it possible?

Another operation i would like to know how to do is delete a row during runtime programatically (by code).

Cant find members to do that.

Thanks a lot.


Kim
Re: Two "basic" operations on GridCtrl [message #21021 is a reply to message #21019] Sun, 26 April 2009 20:46 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1354
Registered: November 2005
Location: Poland
Senior Contributor

kbyte wrote on Sun, 26 April 2009 12:27

Hi all,

I would like to change, during runtime, the text of the columns in the header of the GridCtrl. Is it possible?

Another operation i would like to know how to do is delete a row during runtime programatically (by code).

Cant find members to do that.

Thanks a lot.


Kim

1.
grid.GetColumn(int n).Name("new column name");
grid.RefreshTop();

2.
grid.Remove(int n, int cnt = 1)
grid.RemoveFirst(int cnt = 1);
grid.RemoveLast(int cnt = 1);

Re: Two "basic" operations on GridCtrl [message #21022 is a reply to message #21021] Sun, 26 April 2009 21:17 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
One more question, please:

In what callback can we display a context menu?

In ArrayCtrl we use Grid.WhenBar = THISBACK(OnGridContextMenu)

what about GridCtrl?

Many thanks

Kim
Re: Two "basic" operations on GridCtrl [message #21023 is a reply to message #21022] Sun, 26 April 2009 21:43 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1354
Registered: November 2005
Location: Poland
Senior Contributor

kbyte wrote on Sun, 26 April 2009 15:17

One more question, please:

In what callback can we display a context menu?

In ArrayCtrl we use Grid.WhenBar = THISBACK(OnGridContextMenu)

what about GridCtrl?

Many thanks

Kim

The grid's callback has the same name Smile
You can also use standard context menu but replace action in particular places:
Callback StdInsert;
Callback StdAppend;
Callback StdRemove;
Callback StdDuplicate;
Callback StdEdit;

And you can use standard menu builders in your WhenBar method if you want add only few specific items and still have standard items:
void RemovingMenu(Bar& bar);
void MovingMenu(Bar &bar);
void SelectMenu(Bar &bar);
void ColumnsMenu(Bar &bar);
void ClipboardMenu(Bar &bar)
void PasteAsMenu(Bar &bar);
void NavigatingBar(Bar &bar);
void StdMenuBar(Bar &bar); // this one builds standard menu using methods listed above;

Hopes that will help you Smile

PS: All this remainds me to finish grid documentation..
Re: Two "basic" operations on GridCtrl [message #21024 is a reply to message #21023] Mon, 27 April 2009 00:04 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
[quote
Hopes that will help you Smile

PS: All this remainds me to finish grid documentation..[/quote]

Yes, it does!
Yes, I read the documentation about gridctrl on this site but the last points are not finished yet Wink. I think this great control deserves a complete documentation Wink

Many thanks

Kim
Re: Two "basic" operations on GridCtrl [message #21025 is a reply to message #21024] Mon, 27 April 2009 00:35 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
But Compiler says that GridCtrl do not have WhenBar member

dbGrid.WhenBar = THISBACK(OnGridContextMenu)

as I do for ArrayCtrl.

How is StdMenuBar called from WhenBar?


Kim



Re: Two "basic" operations on GridCtrl [message #21027 is a reply to message #21025] Mon, 27 April 2009 08:47 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1354
Registered: November 2005
Location: Poland
Senior Contributor

kbyte wrote on Sun, 26 April 2009 18:35

But Compiler says that GridCtrl do not have WhenBar member
dbGrid.WhenBar = THISBACK(OnGridContextMenu)
as I do for ArrayCtrl.


Sorry Smile The correct name is WhenMenuBar.
Re: Two "basic" operations on GridCtrl [message #21082 is a reply to message #21027] Sat, 02 May 2009 12:14 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
Hi,

I a trying another feature of the dbgridCtrl but without success

In the dbgrid control I have columns with text, others with numbers other with dates. I need that sorting capability respect the type of the data that the sorted column has.
To the best of my knowledge, dbgrid sorts columns using text data type. What about if we want to cutomize the sorting?

I am trying that with


dbGridCtrl.WhenSort= THISBACK(OnCustomSort);

But, when OnCustomSort is called how do we know which column was click to be sorted?
How to implement custom sort inside OnCustomSort? A simple example would be very appreciated.

One more question please:

Can we "turn off" a callback during runtime?
Like this:

For some moments i need that dbgrid implement custom sorting so i do this:
dbGridCtrl.WhenSort= THISBACK(OnCustomSort);

But when i want to return to the default sorting of the dbgrid, how to turn off this callback?
I tryed to set NULL in WhenSort but compiler complains Sad

Thanks a lot






Kim

[Updated on: Sat, 02 May 2009 12:16]

Report message to a moderator

Re: Two "basic" operations on GridCtrl [message #21115 is a reply to message #21082] Mon, 04 May 2009 09:39 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1354
Registered: November 2005
Location: Poland
Senior Contributor

GridCtrl by default uses StdValueCompare function which is "type aware" - so it sorts properly int, double, boolean, time and date types. Unknown types are converted to string and compare as strings (just take a look at Core/Value.cpp file)
If you want to do your own sorting in WhenSort use GetSortOrder method which returns Vector<SortOrder> - the vector with information about columns clicked by user to sort the grid data.

SortOrder consists of:
int id - id of column (each column has unique id which remain the same no matter of real visual column position)
Id name - Id object connected with column
bool ascending, descendig - direction of sorting (only one is set to true of course)

To remove WhenSort action just write:
grid.WhenSort.Clear();


I implemented WhenSort to being able to react on sort action in scenario when you reload grid data. For example when user clicks column I modify the sql sent to database and the database sorts data and returns it back to the grid. If you would like to sort data already loaded to grid (without clearing grid and populating it again) I'd have to expose internal RowItems collection and I don't want to do this.
So please paste a test case that ilustrate the problem in more datails. We'll try to find a correct solution then.

[Updated on: Mon, 04 May 2009 09:41]

Report message to a moderator

Re: Two "basic" operations on GridCtrl [message #21125 is a reply to message #21115] Mon, 04 May 2009 12:52 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
Here is the whole story:

My application must be international as much as possible.
The main window of the app will show a dbgrid control in the whole main window client area. It is the user that populates this grid. It can choose to load it using a local SQlite database table, It can load it with a CSV file, XML file, etc. So I (the programmer) donít know the type of the data being loaded (just for the local database). So I am aware of the data types and I load dbgrid control with the Add method passing it strings for all the columns.
Once loaded, I want to give the chance to the user of sorting the data by clicking on the column header. This works good for strings but not for columns that contain dates and numbers (stored in the dbgrid as string as I said).

So, which is the most easy solve this?


Kim

[Updated on: Mon, 04 May 2009 12:54]

Report message to a moderator

Re: Two "basic" operations on GridCtrl [message #21126 is a reply to message #21125] Mon, 04 May 2009 13:37 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1354
Registered: November 2005
Location: Poland
Senior Contributor

So if you know data types from the input - just convert strings to Upp types before adding them to the grid. Like this:

FileIn f("data.csv");
int row = 0;
while(!f.IsEof())
{
   Vector<String> v = Split(f.GetLine(), ';');
   for(int i = 0; i < v.GetCount(); i++)
   {
       Value val;
       if(i == 0) // date
       {
           val = Date(v[i].Left(4), v[i].Mid(5, 2), v[i].Right(2));
       } 
       else if(i == 1) // double
       {
           val = StrDbl(v[i]);
       }
       else if(i == 2) // int
       {
           val = StrInt(v[i]);
       }
       else // any other type
         val = AsString(v[i]);
       
      grid.Set(row, i, val);
   }
   ++row; 
}

[Updated on: Mon, 04 May 2009 13:39]

Report message to a moderator

Re: Two "basic" operations on GridCtrl [message #21128 is a reply to message #21126] Mon, 04 May 2009 14:02 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
Great!
For the case of date data type, is there any way to format it to be displayed in some language format while beeing stored as a date value inside gridcontrol (usefull for good sorting operation)?

Thank you

Kim

[Updated on: Mon, 04 May 2009 14:11]

Report message to a moderator

Re: Two "basic" operations on GridCtrl [message #21132 is a reply to message #21128] Mon, 04 May 2009 15:22 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1354
Registered: November 2005
Location: Poland
Senior Contributor

kbyte wrote on Mon, 04 May 2009 08:02

Great!
For the case of date data type, is there any way to format it to be displayed in some language format while beeing stored as a date value inside gridcontrol (usefull for good sorting operation)?


Of course.

struct MyDataConvert : Convert
{
   Value Format(const Value& q) const
   {
       const Data& d = q; 
       return Format("%4d/%2d/%2d", d.year, d.month. d.day);
   }
};

grid.AddColumn("Date column").SetConvert(Single<MyDataConvert>());


Just have a look at reference assembly. There is a nice example about converters.
Re: Two "basic" operations on GridCtrl [message #21133 is a reply to message #21132] Mon, 04 May 2009 15:52 Go to previous messageGo to next message
kbyte is currently offline  kbyte
Messages: 87
Registered: July 2008
Member
Very nice!

Thank you very much.

Kim
Re: Two "basic" operations on GridCtrl [message #40765 is a reply to message #21133] Fri, 13 September 2013 19:35 Go to previous message
pacoquintana is currently offline  pacoquintana
Messages: 12
Registered: December 2011
Location: Spain
Promising Member
I have this problem in displaying date in an arrayCtrl
It gives me an ASSERT error in execution.
Any solutions ?
Thanks
Sad


1add1f71cc45f0a88caa948bf339b589
Previous Topic: ArrayCtrl.AsQtf bug?
Next Topic: LineEdit font bug
Goto Forum:
  


Current Time: Sun Sep 22 20:53:32 CEST 2019

Total time taken to generate the page: 0.01306 seconds