Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TStringGrid OnSetEditText Editing 1

Status
Not open for further replies.

cbuilderer

Programmer
Sep 23, 2007
3
AU
Im using the OnSetEditText event to verify text changes. If something invalid is entered I change the text to a valid value.

The problem is when I change the value, the new value is then highlighted. So if another key press occurs this value gets overridden.

I thought maybe if the TStringGrid received a right key press event then the highlight would go away.

Im trying to limit the cell value to 0..255.

Thanks in advance
 
Show us the code you are using. Maybe that will give us an idea.



James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Thanks,

Here is the code I was using:

void __fastcall TfrmMain::sgSREGSetEditText(TObject *Sender, int ACol, int ARow, const AnsiString Value)
{
int temp;

// Check S-REG values are in range.
if( ACol == SREG_COL_VALUE ) {

// Ensure value is decimal.
temp = Value.ToIntDef(-1);

// Ensure value is between 0 and 255.
if( temp < 0 )
sgSREG->Cells[ACol][ARow] = 0;

else if( temp > 255 )
sgSREG->Cells[ACol][ARow] = 255;

// Clear off leading zeros.
else if( Value.Pos("0") == 1 )
sgSREG->Cells[ACol][ARow] = temp;

// If the value doesn't require changes return.
else return;

// TODO: CANCEL CELL HIGHLIGHT HERE, SO FUTURE KEY PRESSES DON'T OVERRIDE CELL VALUE ????
}
}
 
I'm guessing here but what if you call SelLength to zero (0) for the edit box that the highlight will go away.



James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
That was a good idea unfortunately SelLength isn't a Property of TStringGrid (at least with CB5). With CB5 SelLength is only in TEdit, TComboBox and TRichEdit.

Maybe its included with TStringGrid on newer compilers?
 
You're right. I was thinking about the edit box instead of a string. I'll look around some more.



James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top