如何获取datagridview控件中改变的值? datagridview中有name,age,zip三列,name和zip是string,age是int当它们之下的内容改变时如何让应用程序知道?1,用哪个事件?2,事件响应程序用什么函数获得string和int类型的数据? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ding ding ding ding ding ding CellValueChanged?这个不是你控制他改变的吗 如果绑定到DataTable, 倒是有事件通知。 绑定数据我就不写了。。这个是改哪个cell里的值后得到改变后的值。。private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { string str= Convert.ToString(dataGridView1[e.ColumnIndex, e.RowIndex].Value) ; } 难道不是用datagridview来显示数据库的表的吗?程序运行时,在窗口中改动了表,要把改动的数据存到数据库表中,我是这个意思。要用的哪个事件,用什么函数啊? 千辛万苦啊,终于搞出来了: private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { SqlConnection sc = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlConnection sa = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True"); SqlDataAdapter sda = new SqlDataAdapter("select *from shit", sa); DataSet ds = new DataSet(); SqlCommandBuilder scbld = new SqlCommandBuilder(sda); //sc.Open(); sda.Fill(ds, "temp"); //ds.Tables["temp"].Rows[0]["name"] = "sss"; //int rows=sda.Update(ds, "temp"); int rowindex = e.RowIndex; int columnindex = e.ColumnIndex; //label1.Text = rowindex.ToString() + "行"+columnindex.ToString()+"列"; //string str = Convert.ToString(dataGridView1[e.ColumnIndex, e.RowIndex].t); if (rowindex > -1 && columnindex > -1) { ds.Tables["temp"].Rows[rowindex]["name"] = dataGridView1[1,rowindex].Value.ToString(); ds.Tables["temp"].Rows[rowindex]["age"] = dataGridView1[0,rowindex].Value; ds.Tables["temp"].Rows[rowindex]["zip"] = dataGridView1[2,rowindex].Value.ToString(); //label1.Text = rowindex.ToString() + "行"+columnindex.ToString()+"列"+dataGridView1[rowindex, columnindex].Value.ToString(); //label1.Text = dataGridView1[0, rowindex].ValueType.ToString(); } sda.Update(ds, "temp");} 怎么把汉字组合起来,不重复组合 真正高手帮忙,求c#实现的Delauny三角剖分算法,最好是分治算法实现 想在项目中引入WPF的问题 dataGridView中的checkbox怎么用? 再次发帖求救。。。。。。。。。。。。。 数据库入门问题! datagrid中用checkbox显示数据库中bit字段的数据 C#用Graphics在PictureBox上绘制图形时绘制到一半的时候Form变成白色的,想立即结束程序时的样子,怎么解决? 谁能帮忙给个水晶报表9的注册码,谢谢! 有没有软件可以阅读 .chm 文件 线程池,异步的一个小问题! 有没有人做过邮件客户端的程序呀
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
string str= Convert.ToString(dataGridView1[e.ColumnIndex, e.RowIndex].Value) ;
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
SqlConnection sc = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlConnection sa = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select *from shit", sa);
DataSet ds = new DataSet();
SqlCommandBuilder scbld = new SqlCommandBuilder(sda);
//sc.Open();
sda.Fill(ds, "temp");
//ds.Tables["temp"].Rows[0]["name"] = "sss";
//int rows=sda.Update(ds, "temp");
int rowindex = e.RowIndex;
int columnindex = e.ColumnIndex;
//label1.Text = rowindex.ToString() + "行"+columnindex.ToString()+"列";
//string str = Convert.ToString(dataGridView1[e.ColumnIndex, e.RowIndex].t);
if (rowindex > -1 && columnindex > -1)
{
ds.Tables["temp"].Rows[rowindex]["name"] = dataGridView1[1,rowindex].Value.ToString();
ds.Tables["temp"].Rows[rowindex]["age"] = dataGridView1[0,rowindex].Value;
ds.Tables["temp"].Rows[rowindex]["zip"] = dataGridView1[2,rowindex].Value.ToString();
//label1.Text = rowindex.ToString() + "行"+columnindex.ToString()+"列"+dataGridView1[rowindex, columnindex].Value.ToString();
//label1.Text = dataGridView1[0, rowindex].ValueType.ToString();
}
sda.Update(ds, "temp");
}