 |
|
 |
I thought I would have to do this to get what I wanted; to find someone else had already accomplished this work, and better implemented than I would have, was a very pleasant surprise. Well spelled out instructions on use too! 5 stars!
|
|
|
|
 |
|
 |
Hello:
I have a GridCtrl and I'm working in virtual mode.
I have tried to editing a cell as numeric but I can´t. I need help. What's wrong here??
void CGuardarShapeFileDlg::OnVirtualMode()
{
UpdateData();
.........
m_Grid.SetEditable(TRUE);
col = 1;
for (row = 1;row < m_nRows ;row++)
{
m_Grid.SetCellType(row , col, RUNTIME_CLASS(CGridCellNumeric));
}
Thanks
Ana
|
|
|
|
 |
|
 |
I get this error on vs2005
gridctrl\gridcellnumeric.cpp(798) : error C2440: 'initializing' : cannot convert from 'const char *' to 'TCHAR *'
Conversion loses qualifiers
GridCtrl.cpp
How can I fix this? Is it compiler settings?
|
|
|
|
 |
|
 |
I had a big explanation of the error all typed up and when I hit the "Post Message" button CP decided to crap out on me and the explanation was lost. I am not going to typ it out again. See here[^] and here[^].
Changing TCHAR *ptr to LPCTSTR ptr should fix the problem.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
 |
|
 |
Thanx a lot, that got it fixed. Although I couldnt catch up with the explanation
|
|
|
|
 |
|
 |
The only time my wife ever swears is when that happens, and she outdoes me when she loses a post.
I don't blame you, wish I could have seen the long answer, but the short answer worked.
|
|
|
|
 |
|
 |
How do I delete a row? I have a grid in list mode with one column as currency, but when I try to delete the contents of the row (by selecting the row, then pressing DEL) the program crashes.
|
|
|
|
 |
|
 |
Calling CGridCtrl::DeleteRow() should be all it takes. What do you mean by "crashes"? Do you get an ASSERT in debug mode? Does the code throw an unhandled exception? Does the program just quit with no errors? Is it crashing in CGridCellNumeric's code?
More info is needed if you want me to be able to help you.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
 |
|
 |
I do not know how to do the math using this wonderful NumericGridCellCtr. Supposed I have three cells like cell1, cell2 and cell3, but I want cell3 as a result of cell1 + cell2. How to do that?
Thanx.
|
|
|
|
 |
|
 |
Unfortunately this cell is not a spreadsheet like cell, it does not take formulas. But what it does have is GetNumber() and SetNumber() members.
Something like this should do what you want:CGridCellNumeric *pCell1 = dynamic_cast<CGridCellNumeric *>(GetCell(row1, col1));
CGridCellNumeric *pCell2 = dynamic_cast<CGridCellNumeric *>(GetCell(row2, col2));
CGridCellNumeric *pCell3 = dynamic_cast<CGridCellNumeric *>(GetCell(row3, col3));
if (pCell1 && pCell2 && pCell3)
{
pCell3->SetNumber(pCell1->GetNumber() + pCell2->GetNumber());
}
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
 |
|
 |
I tried with locale set to english and it works. But when set to my local which uses comma as separator, cell rejects it.
|
|
|
|
 |
|
 |
What do you mean by "rejects it"? I have tried this cell with several locales (I will admit not all of them) and have had no problems. The only problem I have noticed is when I try to drag a value that has a comma in it. But that is because the gridctrl itself does not handle dragging cells with commas in them very well.
If you let me know which locale you are using I can maybe tell you what the problem is.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
 |
|
 |
My locale is set to Slovenian. In CGridCellNumeric.Format function you replace ',' with '.' in str and then call
double Number = _tcstod(str, &EndPtr);
I think _tcstod expects locale decimal separator.
|
|
|
|
 |
|
 |
According to MSDN it does, but when I set my machine to a locale that uses commas instead of periods (W2K via Control Panel->Regional Options) the _tcstod function fails if the string has a comma in it.
There must be something I am missing, I will more into it when I have the time.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
 |
|
 |
Yes, you are right, I have the same problem with
a German locale setting. The CGridCellNumeric.Format
function is buggy concerning this. Did you find a
solution meanwhile?
Raimund
|
|
|
|
 |
|
 |
Hey Raimund,
I think this locale aware stuff is a little bit more work than I had anticipated, but I do want to get it working. Can you try the following code and let me know if it works?
What I am now doing is replacing the user locale decimal point with the system decimal point, rather than with a period as was done previously.
BOOL CGridCellNumeric::Format(CString &TheString)
{
int count = 0;
CString str = TheString;
CString buffer;
CString sDigits;
TCHAR cDecimal = 0;
TCHAR cSystemDecimal = 0;
TCHAR cNegative = 0;
int iNegative = -1;
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SNATIVEDIGITS,
NULL,
0);
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SNATIVEDIGITS,
sDigits.GetBuffer(count),
count);
sDigits.ReleaseBuffer();
if (!count)
sDigits = _T("0123456789");
if (m_dwFlags & Currency)
{
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SMONDECIMALSEP,
NULL,
0);
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SMONDECIMALSEP,
buffer.GetBuffer(count),
count);
buffer.ReleaseBuffer();
cDecimal = count ? buffer[0] : _T('.');
sDigits += cDecimal;
count = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,
LOCALE_SMONDECIMALSEP,
NULL,
0);
count = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,
LOCALE_SMONDECIMALSEP,
buffer.GetBuffer(count),
count);
buffer.ReleaseBuffer();
cSystemDecimal = count ? buffer[0] : _T('.');
sDigits += cDecimal;
}
else
{
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SDECIMAL,
NULL,
0);
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SDECIMAL,
buffer.GetBuffer(count),
count);
buffer.ReleaseBuffer();
cDecimal = count ? buffer[0] : _T('.');
count = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,
LOCALE_SDECIMAL,
NULL,
0);
count = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,
LOCALE_SDECIMAL,
buffer.GetBuffer(count),
count);
buffer.ReleaseBuffer();
cSystemDecimal = count ? buffer[0] : _T('.');
}
if (m_dwFlags & Negative)
{
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SNEGATIVESIGN,
NULL,
0);
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SNEGATIVESIGN,
buffer.GetBuffer(count),
count);
buffer.ReleaseBuffer();
cNegative = count ? buffer[0] : _T('-');
sDigits += cNegative;
if (m_dwFlags & Currency)
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_INEGCURR | LOCALE_RETURN_NUMBER,
(LPTSTR)&iNegative,
sizeof(int) / sizeof(TCHAR));
else
count = GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_INEGNUMBER | LOCALE_RETURN_NUMBER,
(LPTSTR)&iNegative,
sizeof(int) / sizeof(TCHAR));
if (!count)
iNegative = 1;
if (m_dwFlags & Currency)
{
if (iNegative == 0 || iNegative == 4 || iNegative == 14 || iNegative == 15)
sDigits += _T("()");
}
else if (iNegative == 0)
sDigits += _T("()");
}
if (m_dwFlags & (Real | Currency))
{
str.Replace(cDecimal, cSystemDecimal);
sDigits += cSystemDecimal;
}
if ((m_dwFlags & TypeMask) == Integer)
{
int pos = str.Find(_T('.'), 0);
if (pos != -1)
str.Delete(pos, str.GetLength() - pos);
}
LPCTSTR digits = sDigits;
for(int i = str.GetLength() - 1; i >= 0; --i)
{
TCHAR *ptr = _tcschr(digits, str[i]);
if (ptr == NULL)
str.Delete(i);
else
{
int diff = (int)(ptr - digits);
if (diff < 10 && (*ptr < _T('0') || *ptr > _T('9')))
{
TCHAR ch = (TCHAR)(0x30 + diff);
str.SetAt(i, ch);
}
}
}
if (m_dwFlags & Negative)
{
CString neg = (iNegative ? _T("") : _T("()"));
neg += cNegative;
if (str.FindOneOf(neg) != -1)
{
str.Remove(cNegative);
str.Remove(_T('('));
str.Remove(_T(')'));
str.Insert(0, _T('-'));
}
}
TCHAR *EndPtr = NULL;
double Number = _tcstod(str, &EndPtr);
str.Replace(cSystemDecimal, _T('.'));
if (*EndPtr == NULL)
{
CString Formatted;
if (m_dwFlags & Currency)
{
count = GetCurrencyFormat(LOCALE_USER_DEFAULT,
NULL,
str,
m_pCurrencyFmt,
NULL,
0);
count = GetCurrencyFormat(LOCALE_USER_DEFAULT,
NULL,
str,
m_pCurrencyFmt,
Formatted.GetBuffer(count),
count);
Formatted.ReleaseBuffer();
}
else
{
count = GetNumberFormat(LOCALE_USER_DEFAULT,
NULL,
str,
m_pNumberFmt,
NULL,
0);
count = GetNumberFormat(LOCALE_USER_DEFAULT,
NULL,
str,
m_pNumberFmt,
Formatted.GetBuffer(count),
count);
Formatted.ReleaseBuffer();
}
if (count)
{
if ((m_dwFlags & TypeMask) == Integer)
{
int pos = Formatted.Find(cDecimal, 0);
if (pos != -1)
{
Formatted.Delete(pos);
while (pos < Formatted.GetLength() && Formatted[pos] == sDigits[0])
Formatted.Delete(pos);
}
}
m_nNumber = Number;
TheString = Formatted;
return TRUE;
}
}
TRACE (_T("CGridCellNumeric::Format() - Failed to correctly format string."));
return FALSE;
}
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
 |
|
 |
I've just downloaded the sources and with my locale set to german it works perfectly with commas. Were any changes to the sources made after this discussion?
|
|
|
|
 |
|
 |
ABuenger wrote:
Were any changes to the sources made after this discussion?
No, I never heard anything back after I posted the proposed fix so I did not know if it was working or not, so I had nothing to update. The control works great for what I am using it for, but I am sure it could use a lot of improvement. I like to think that CP is about collaboration so if you (or anyone else who reads this) has any ideas or bug fixes, implement them and post the fixes on this forum. Together we can make great things;)
I am glad to hear that you have it working, thanks for letting me know
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
 |
|
 |
PJ Arends wrote:
if you (or anyone else who reads this) has any ideas or bug fixes, implement them and post the fixes on this forum
I need some features which i will implement tomorrow or later this week:
- Disable the thousand separator by adding a static NUMBERFMT pointer to the class. The Format method then looks first for the member pointer and then for the static pointer. That way a default NUMBERFMT can be set as well as a individual for each cell.
- Adding GetInteger / SetInteger methods. (It's annoying to cast the values every time)
|
|
|
|
 |
|
 |
PJ Arends wrote: I like to think that CP is about collaboration so if you (or anyone else who reads this) has any ideas or bug fixes, implement them and post the fixes on this forum. Together we can make great thingsWink
What about adding scientific notation as well to floating point numbers
In the case I do it, I will let you know
Have a nice day
-- Ricky Marek (AKA: rbid)
-- "Things are only impossible until they are not" --- Jean-Luc Picard
My articles
|
|
|
|
 |
|
 |
BugSearcher wrote:
Why haven't you uploaded one.
Size was the main reason, and I didn't think it would be too hard to to download Chris's code and slap my code into it. But you are right I should have included one. I have slapped a demo app together and have sent to CP. The article should be updated soon.
In the mean time, you can get it at http://www3.telus.net/pja/PJAGridCellNumeric_demo.zip - 216 KB
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
 |
|
 |
Looks to be a good work. I haven't voted as yet. The reason I am posting is that I generally download and see the demo project with the articles. Why haven't you uploaded one.
Imagine that you are creating a fabric of human destiny with the object of making men happy in the end, giving them peace and rest at last, but that it was essential and inevitable to torture to death only one tiny creature..and to found that edifice on its unavenged tears, would you consent to be the architect on those conditions? Tell me, and tell me the truth!
-Fyodor Dostoevsky, The Brothers Karamazov
|
|
|
|
 |
|
 |
Your download don't work!
|
|
|
|
 |
|
 |
Works fine now. Maybe the editors fixed the link when they edited the article.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
 |