我有一个datagridview连接到数据库.我有一个复选框,用于在datagridview中启用数据编辑.如果选中该复选框,则只能编辑1列datagridview,编辑后单击"保存"按钮将其反映在数据库中,当取消选中复选框时,将禁用编辑.
我尝试过这样的事情:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.CheckState == CheckState.Checked)
{
dataGridView1.CurrentRow.ReadOnly = false;
dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
}
else if (checkBox1.CheckState == CheckState.Unchecked)
{
dataGridView1.ReadOnly = true;
}
}
Run Code Online (Sandbox Code Playgroud)
此代码忽略了选择要编辑的列的概念.
我已尝试将此代码从textbox1.text和textbox2.text添加到textbox3.text中
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
{
textBox3.Text = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text).ToString());
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
{
textBox3.Text = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text).ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
请帮助...有没有什么比将文本框的'格式'属性更改为一般数字?