Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » GridCtrl empty cells pasted from Excel
Re: GridCtrl empty cells pasted from Excel [message #17696 is a reply to message #17694] |
Tue, 26 August 2008 12:08   |
|
koldo wrote on Tue, 26 August 2008 05:16 | Hello unodgs
Sorry. I have found the problem in my program but I do not know how to fix it.
The problem comes from a field with "SetDisplay" that gets the exception when pasting from Notepad and corrupts the Date field beside it as described in the posts.
For example this works right:
myGridCtrl.AddColumn(ISMARRIED, t_("Is married?")).Edit(isMarried).Default(-1);
and this wrong:
myGridCtrl.AddColumn(ISMARRIED, t_("Is married?")).SetDisplay(Single<DispPM>()).Edit(isMarried).Default(-1);
|
in this case much better is to use conveter. DropGrid implements Convert interface so you can just write:
myGridCtrl.AddColumn(ISMARRIED, t_("Is married?")).Edit(isMarried).SetConvert(isMarried).Default(-1);
or in short form
myGridCtrl.AddColumn(ISMARRIED, t_("Is married?")).EditConvert(isMarried).Default(-1);
Quote: |
isMarried is declared this way:
DropGrid isMarried;
And initialized this way:
isMarried.Add(1, t_("Yes")).Add(-1, t_("No"));
So I want to store an integer from a DropGrid with strings.
Going to DisPM, as I want to see "Yes" or "No" in the cells, this is the original version that works properly with rows copied directly from GridCtrl but gets an exception if copied from Notepad:
struct DispPM : GridDisplay
{
virtual void Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style, Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe)
{
String text;
if(!val.IsNull())
text = int(val) > 0 ? "Yes" : "No";
else
text = "";
GridDisplay::Paint(w, x, y, cx, cy, Value(text), style, fg, bg, fnt, found, fs, fe);
}
};
This other version lets paste from Notepad but does not show "Yes" or "No" but empty cells
struct DispPM : GridDisplay
{
virtual void Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style, Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe)
{
w.DrawRect(x, y, cx, cy, bg);
if(!val.IsNull())
w.DrawText(x, y, int(val) > 0 ? "Yes" : "No", fnt, fg);
GridDisplay::Paint(w, x, y, cx, cy, Value(""), style, fg, bg, fnt, found, fs, fe);
}
};
Do you have any idea?
|
When you paste data from excel clipboard you in fact copy String values into the grid's cells. Now in your code you cast String value to int value and there is your exception. In DropGrid case everything is fine as it stores in cell integer value.
It's a serious problem. I think grid should provide WhenPasteCell(int x, int y, Value& v) callback when you could convert String value object to proper type (like int). I'll try to do sth with it. Maybe I'll add some kind of auto conventer too.
|
|
|
 |
|
GridCtrl empty cells pasted from Excel
By: koldo on Sat, 09 August 2008 01:11
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: koldo on Mon, 25 August 2008 12:31
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: unodgs on Mon, 25 August 2008 14:37
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: unodgs on Mon, 25 August 2008 14:51
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: unodgs on Mon, 25 August 2008 15:07
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: koldo on Mon, 25 August 2008 22:02
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: unodgs on Mon, 25 August 2008 23:03
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: koldo on Tue, 26 August 2008 11:16
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: unodgs on Tue, 26 August 2008 12:08
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: koldo on Tue, 26 August 2008 12:07
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: koldo on Tue, 26 August 2008 16:11
|
 |
|
Re: GridCtrl empty cells pasted from Excel
By: koldo on Tue, 26 August 2008 16:24
|
Goto Forum:
Current Time: Sun Aug 24 15:20:17 CEST 2025
Total time taken to generate the page: 0.06291 seconds
|