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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AnsiString VK_RETURN

Status
Not open for further replies.

jcb184

Programmer
Aug 26, 2005
5
US
Hello,

Firstly - Nice forum!

My question: I'm using TStringGrid. When a user edits a cell, I call the SetEditText() Method. It passes me AnsiString of value entered in the cell.

What I would like to do, is if the AnsiString Value is [enter] - do something.

Normally I would do something like if (String == VK_RETURN), but it of course does not work with AnsiString.

What is the correct way to implement such functionality? (I want to catch when user presses return inside a cell)

Thanks in advance. I'm sorry - I'm new to Borland and C++ In general.
 
you do all the key comparisons in the
StringGridKeyDown and the StringGridOnKeyPress
method. this is were you get the key presses
to process

just a cut and paste of some of my code I
am working on. its a mess but you might get
the drift.

Code:
void __fastcall MHDBVisual::StringGridKeyDown(TObject *Sender, WORD &Key,
                            TShiftState Shift)
{
    //key = false;
    try
    {
        // Press the enter key to post the modified record
        if (Key == VK_RETURN)
        {
            PostClick(Sender);
        }
        // test for a paste operation
        else if ((Modified == false) && (_Edit == true))
        {

            if (Shift.Contains(ssShift));
                //key = true;
            else if (Shift.Contains(ssAlt));
                //key = true;
            else if (Shift.Contains(ssCtrl))
            {
                // a paste operation has been performed
                if (Shift.Contains(ssCtrl) && Key == 'V')
                    modified ();

                //key = true;
            }
        }
    }
    catch (...)
    {
        ShowMessage ("An Error occured on StringGridKeyDown ().\nVisual class error.");
    }
}

Code:
void __fastcall MHDBVisual::StringGridOnKeyPress (TObject *Sender, char &Key)
{
    if ((signed)strlen (StrGrid->Cells[field][RecNo + 1].c_str ()) < fieldsize)
    {
        // The first key press to modify the record
        if ((Modified == false) && (_Edit == true))// && (key == false))
            modified ();

        fieldcounter++;

        //ShowMessage (StrGrid->Cells[field][RecNo + 1]);
    }
    else
        Key = NULL;

}
 
I'm a little confused - I don't see StringGridKeyDown() listed as a method for TStringGrid in the Borland Documentation, nor when searching do I get any results from the documentation..?
 
I see OnKeyDown and it seems that would work - but this event doesn't pass the column and row to the function - so how is it known what row/column the user pressed enter (VK_RETURN) in?
 
Well, I worked around this by using OnSetEditText to write the column/row to a few variables - that way when KeyDown catches the [return], I know what cell column/row the return key was entered in.

I am not sure this is the right way to do things though..
 
the row/col property is set when you click
on the cell of the stringrid. these objects
dont have any events directly linked to them.

when you click on the stringgrid these properties
are set. then you can access the cell.

Edit1->Text = StrGrid->Cells[StrGrid->Col][StrGrid->Row];

you know what cell the keypress happened in because
StrGrid->Row has a value of the row the cell is on.
StrGrid->Col has the value of the Col the cell is on.

pardon, when you clik the onkeydown event in the object
inspector it generates the StringGridKeyDown method.
Code:
void __fastcall Tform1::StringGridKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{


}


TC
 
Ah, I see. Thanks for the information!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top