我需要编写一个简单的函数,当人输入框数时,然后按下按键事件并number of boxes*someamount进入金额列.我使用拖放控件添加了datagridview

我想根据我的研究,这里将编写代码
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e) {
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何把Keyup事件和访问列numberofboxes and Amount.谢谢
我已经测试了这个并且它通过使用按键事件工作并且将NumberBoxes值乘以someAmount,每次在单元格中输入新数字时它会自动为您计算.
public Form1()
{
InitializeComponent();
MyDataGridViewInitializationMethod();
}
private void MyDataGridViewInitializationMethod()
{
dataGridView1.EditingControlShowing +=
new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.KeyPress +=
new KeyPressEventHandler(Control_KeyPress);
}
private void Control_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsNumber(e.KeyChar))
{
string cellValue = Char.ToString(e.KeyChar);
//Get the column and row position of the selected cell
int column = dataGridView1.CurrentCellAddress.X;
int row = dataGridView1.CurrentCellAddress.Y;
if (column == 1)
{
//Gets the value that existings in that cell
string test = dataGridView1[column, row].EditedFormattedValue.ToString();
//combines current key press to the contents of the cell
test = test + cellValue;
int intNumberBoxes = Convert.ToInt32(test);
//Some amount to mutiple the numberboxes by
int someAmount = 10;
dataGridView1[column + 1, row].Value = intNumberBoxes * someAmount;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12382 次 |
| 最近记录: |