Datagrid keypress handling

  • Thread starter Thread starter apemen
  • Start date Start date
A

apemen

Hi,
I need to handle keypress event to calculate total of a cells of a column.
I used datagrid_onkeypress, placed a breakpoint, but it did not enter
function when I edited the cell. Instead it enters when clicked row header.

Secondly, I could not handle the "DEL" key. I must prevent user
from to delete a row using the "DEL" key.

Thank you for your helps.
 
Hi,

Inherit from DataGrid and override:

OnProcessCmdKey
OnProcessDialogKey
OnProcessKeyPreview

All these methods are called to handle keystrokes, but under different
circumstances. In particular, the third one is called when a cell is being
edited.
 
It solved "DEL" key problem, thank you.
But another thing I am trying to do is that,
when user changes,say amount of product,updating total price.
So
if (keyData in DecimalKeys(I defined that))
{
base.ProcessCmdKey(....
this.UpdatePrices();
}

but problem is UpdatePrices process with old cell value.
If we do not user ProcessCmdKey with return true or false
it does not process user input?? (may be wrong)

Do you have any idea? or another solution for displaying price changes
dynamicly?

Thank you again.

Dmitriy Lapshin said:
Hi,

Inherit from DataGrid and override:

OnProcessCmdKey
OnProcessDialogKey
OnProcessKeyPreview

All these methods are called to handle keystrokes, but under different
circumstances. In particular, the third one is called when a cell is being
edited.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

apemen said:
Hi,
I need to handle keypress event to calculate total of a cells of a column.
I used datagrid_onkeypress, placed a breakpoint, but it did not enter
function when I edited the cell. Instead it enters when clicked row header.

Secondly, I could not handle the "DEL" key. I must prevent user
from to delete a row using the "DEL" key.

Thank you for your helps.
 
if (keyData in DecimalKeys(I defined that))
{
base.ProcessCmdKey(....

At this point you should "remember" the value returned by the base method.
this.UpdatePrices();
}

And at this point, the grid most likely hasn't had a chance yet to update
the underlying data source. You should listen to data source events to react
on changed prices.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

apemen said:
It solved "DEL" key problem, thank you.
But another thing I am trying to do is that,
when user changes,say amount of product,updating total price.
So
if (keyData in DecimalKeys(I defined that))
{
base.ProcessCmdKey(....
this.UpdatePrices();
}

but problem is UpdatePrices process with old cell value.
If we do not user ProcessCmdKey with return true or false
it does not process user input?? (may be wrong)

Do you have any idea? or another solution for displaying price changes
dynamicly?

Thank you again.

Dmitriy Lapshin said:
Hi,

Inherit from DataGrid and override:

OnProcessCmdKey
OnProcessDialogKey
OnProcessKeyPreview

All these methods are called to handle keystrokes, but under different
circumstances. In particular, the third one is called when a cell is being
edited.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

apemen said:
Hi,
I need to handle keypress event to calculate total of a cells of a column.
I used datagrid_onkeypress, placed a breakpoint, but it did not enter
function when I edited the cell. Instead it enters when clicked row header.

Secondly, I could not handle the "DEL" key. I must prevent user
from to delete a row using the "DEL" key.

Thank you for your helps.
 
Back
Top