PDA

View Full Version : KeyDown_Enter



مهدی هادیان2
شنبه 08 بهمن 1390, 12:01 عصر
بسم الله الرحمن الرحیم
با سلام
می خوام با زدن اینتر به سلول بعدی بره و اگه آخرین سلول بود به سطر بعدی بره
در اون تاپیکی که 18 تا صفحه بود تک تکش رو خوندم:گیج:
ولی راجع به این قضیه کدی رو دیدم که ناقص بود:متفکر:
در ضمن یه تکه کد هم دیدم به شکل زیر ولی نمی دونم در کجا باید استفاده کنم؟

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData)
{
case Keys.Enter:
try
{
dataGridView.CurrentCell = dataGridView[dataGridView.CurrentCell.ColumnIndex + 1,
dataGridView.CurrentCell.RowIndex];
}
catch { } return true;
case Keys.Right:
try
{
dataGridView.CurrentCell = dataGridView[dataGridView.CurrentCell.ColumnIndex - 1,
dataGridView.CurrentCell.RowIndex];
}
catch { } return true;
case Keys.Left:
try
{
dataGridView.CurrentCell = dataGridView[dataGridView.CurrentCell.ColumnIndex + 1,
dataGridView.CurrentCell.RowIndex];
}
catch { } return true;
case Keys.Up:
try
{
dataGridView.CurrentCell = dataGridView[dataGridView.CurrentCell.ColumnIndex,
dataGridView.CurrentCell.RowIndex - 1];
}
catch { } return true;
case Keys.Down:
try
{
dataGridView.CurrentCell = dataGridView[dataGridView.CurrentCell.ColumnIndex,
dataGridView.CurrentCell.RowIndex + 1];
}
catch { } return true;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}

با تشکر