你好,大家好我試圖在這樣的winform DataGrid中......如何更新行值DataGrid中動態地在winform
所以到現在,我能夠顯示數據網格數據,如這
IAM正從數據庫中的所有值... ,所以我想那是什麼,如果我點擊+按鈕,然後這是硬編碼值必須增加一個數量列的值d總量也必須進行更新,但是這應該是隻有前端....
這裏是我的代碼..
公共無效getsubitemdetails(){
string selectSql = "select ItemGroupsAssociations.Price, Items.ItemName from ItemGroupsAssociations INNER JOIN Items ON ItemGroupsAssociations.ItemId = Items.ItemId where ItemGroupsAssociations.CategoryId=1 AND ItemGroupsAssociations.ItemId=1";
//string selectSql = "select * from Categories";
SqlCommand cmd = new SqlCommand(selectSql, con);
try
{
con.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
// int id = Convert.ToInt32(reader["CategoryId"]);
string Categoryname = (reader["ItemName"].ToString());
Price = Convert.ToInt32(reader["Price"]);
int quantity = 2;
int totalamount = quantity * Price;
dataGridView1.ColumnCount = 1;
dataGridView1.Columns[0].Name = "Name";
dataGridView1.Columns[0].Width = 300;
dataGridView1.Rows.Add(Categoryname);
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn);
btn.HeaderText = "Quantity";
btn.Text = quantity.ToString();
btn.Width = 50;
btn.Name = "btn1";
btn.UseColumnTextForButtonValue = true;
DataGridViewButtonColumn btn1 = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn1);
btn1.HeaderText = "Rate";
btn1.Text = Price.ToString();
btn1.Width = 50;
btn1.Name = "btn2";
btn1.UseColumnTextForButtonValue = true;
DataGridViewButtonColumn btn2 = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn2);
btn2.HeaderText = "Total Amount";
btn2.Text = totalamount.ToString();
btn2.Width = 100;
btn2.Name = "btn2";
btn2.UseColumnTextForButtonValue = true;
DataGridViewButtonColumn btn3 = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn3);
btn3.HeaderText = "";
btn3.Text = "+";
btn3.Width = 50;
btn3.Name = "btn3";
btn3.UseColumnTextForButtonValue = true;
}
}
}
finally
{
con.Close();
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4)
{
Price= Price+1;
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " Column button clicked ");
}
}
我怎樣才能實現這一點...請幫助我,這將是偉大的幫助或任何其他建議,以便我可以使用...
謝謝你們。