c# DataGrid 修改某个单元格数据
3个回答
展开全部
privatevoid dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (dataGridView1.CurrentCell !=null)
{
int rowIndex=dataGridView1.CurrentCell.RowIndex;
int colIndex=dataGridView1.CurrentCell.ColumnIndex;
if (colIndex != dataGridView1.ColumnCount -1)
{
dataGridView1.CurrentCell = dataGridView1.Rows[rowIndex].Cells[colIndex +1];
}
else
{
dataGridView1.Rows.Add();
dataGridView1.CurrentCell = dataGridView1.Rows[rowIndex +1].Cells[0];
}
}
}
}
COPY的,这个看代码可以,本人没试!
{
if (e.KeyCode == Keys.Enter)
{
if (dataGridView1.CurrentCell !=null)
{
int rowIndex=dataGridView1.CurrentCell.RowIndex;
int colIndex=dataGridView1.CurrentCell.ColumnIndex;
if (colIndex != dataGridView1.ColumnCount -1)
{
dataGridView1.CurrentCell = dataGridView1.Rows[rowIndex].Cells[colIndex +1];
}
else
{
dataGridView1.Rows.Add();
dataGridView1.CurrentCell = dataGridView1.Rows[rowIndex +1].Cells[0];
}
}
}
}
COPY的,这个看代码可以,本人没试!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dadaGridView.row[0].cell[0].value="你想要修改成的值";
这是修改第一行的第一个单元格
这是修改第一行的第一个单元格
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
string msg = String.Format("编辑表格 ({0}, {1})", e.ColumnIndex, e.RowIndex);
this.Text = msg;
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string msg = String.Format("完成编辑 ({0}, {1})", e.ColumnIndex, e.RowIndex);
this.Text = msg;
}
这是一种方法单元格改变时候的触发事件
try
{
string strQuery = "select * from shuju ";
SqlConnection objConn
= new SqlConnection("server=UNICOM-DELL2-PC;database=test;user id=sa;pwd=sa;");
objConn.Open();
myDataAdapter = new SqlDataAdapter(strQuery, objConn);
//myDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
SqlCommandBuilder custCB = new SqlCommandBuilder(myDataAdapter);
custDS = new DataSet();
myDataAdapter.Fill(custDS, "shuju ");
//code to modify data in dataset here
myDataAdapter.Update(custDS, "shuju ");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
这是另一个的单击事件的方法,其中数据库需要修改
{
string msg = String.Format("编辑表格 ({0}, {1})", e.ColumnIndex, e.RowIndex);
this.Text = msg;
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string msg = String.Format("完成编辑 ({0}, {1})", e.ColumnIndex, e.RowIndex);
this.Text = msg;
}
这是一种方法单元格改变时候的触发事件
try
{
string strQuery = "select * from shuju ";
SqlConnection objConn
= new SqlConnection("server=UNICOM-DELL2-PC;database=test;user id=sa;pwd=sa;");
objConn.Open();
myDataAdapter = new SqlDataAdapter(strQuery, objConn);
//myDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
SqlCommandBuilder custCB = new SqlCommandBuilder(myDataAdapter);
custDS = new DataSet();
myDataAdapter.Fill(custDS, "shuju ");
//code to modify data in dataset here
myDataAdapter.Update(custDS, "shuju ");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
这是另一个的单击事件的方法,其中数据库需要修改
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询