|
|
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  |
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   |
|
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 #21023 is a reply to message #21022] |
Sun, 26 April 2009 21:43   |
|
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 
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 
PS: All this remainds me to finish grid documentation..
|
|
|
|
|
|
Re: Two "basic" operations on GridCtrl [message #21082 is a reply to message #21027] |
Sat, 02 May 2009 12:14   |
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 
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   |
|
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:
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   |
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   |
|
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 #21132 is a reply to message #21128] |
Mon, 04 May 2009 15:22   |
|
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.
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 12:13:34 CEST 2025
Total time taken to generate the page: 0.01100 seconds
|
|
|