Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » How to get edit data in virtual ArrayCtrl?
Re: How to get edit data in virtual ArrayCtrl? [message #9807 is a reply to message #9798] |
Thu, 31 May 2007 11:42   |
|
Thank you very much.
I had a hard time figuring out all those assertions I got when navigating while editing, but looking through the sources I finally understood how it should work.
I ended up with the following two Convert classes:
class VirtualField : public Convert
{
private:
int col;
GridData *map;
public:
VirtualField(int aCol, GridData *pMap)
{
col = aCol;
map = pMap;
}
virtual Value Format(const Value& q) const
{
return map->Get(col, q); // Convert index to value when showing.
}
};
class VirtualEdit : public Convert
{
private:
int col;
GridData *map;
ArrayCtrl *array;
public:
VirtualEdit(int aCol, GridData *pMap, ArrayCtrl *pArray)
{
col = aCol;
map = pMap;
array = pArray;
}
virtual Value Format(const Value& q) const
{
return map->Get(col, array->GetCursor()); // Edit always at cursor, so return value to edit.
}
virtual Value Scan(const Value& text) const
{
map->Set(col, array->GetCursor(), text); // Store value after edit.
return text;
}
};
And then adding the conversion objects when populating:
class CANtrakTexts : public WithCANtrakTextsLayout<TopWindow> {
private:
Array<EditString> edits;
Array<Convert> converts;
GridData map;
....
void CANtrakTexts::PopulateGrid()
{
text_grid.Reset();
edits.Clear();
converts.Clear();
for (int i=0 ; i < map.GetColumnCount() ; i++)
{
edits.Add().SetConvert(converts.Add(new VirtualEdit(i, &map, &text_grid)));
text_grid.AddRowNumColumn(map.GetColumn(i), 180).Edit(edits[edits.GetCount()-1]).SetConvert(converts.Add(new VirtualField(i, &map)));
}
text_grid.SetVirtualCount(map.GetRowCount());
}
BTW: Is it ok to use the Array container to hold my edit and convert objects? Is it obsolete or can it be done smarter?
Coming from Delphi I'm thinking in callbacks and I was actually looking for something like WhenShowVirtualData(int col, int row) and WhenAcceptEdit(int col, int row, String val) or something like that. That would have required much less coding in my case...
Steffen
|
|
|
Goto Forum:
Current Time: Thu Jul 17 23:39:21 CEST 2025
Total time taken to generate the page: 0.03941 seconds
|