我想建立一个旅馆杂费支付系统。假设有五个男孩成群地吃着食物,他们得到了5美元的账单。
我想通过网格视图选择5个成员,我希望5美元平均分配并添加到boys帐户中。在我的代码中,我想在Cnic的帮助下选择男孩,然后在数量上添加TextBox值。
如何在gridview中选择多行并以金额添加文本框值?我想在Cnic的帮助下更新数量。谁能帮我,这是代码:
namespace Mess_system
{
public partial class Payment : Form
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-TTGKCGB;Initial Catalog=hostelmesssystem;Integrated Security=True");
public Payment()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.MultiSelect = true;
}
private void Payment_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'hostelmesssystemDataSet5.Registration' table. You can move, or remove it, as needed.
this.registrationTableAdapter.Fill(this.hostelmesssystemDataSet5.Registration);
//AddHeaderCheckBox();
//HeaderCheckBox.MouseClick += new `enter code here`MouseEventHandler(HeaderCheckBox_MouseClick);
}
//CheckBox HeaderCheckBox = null;
//bool IsHeaderCheckBoxClicked = false;
//private void AddHeaderCheckBox()
//{
// HeaderCheckBox = new CheckBox();
// HeaderCheckBox.Size = new Size(15,15);
// //Add Checkbox in the grid view
// this.dataGridView1.Controls.Add(HeaderCheckBox);
//}
private void gridview()
{
SqlCommand cmd1 = new SqlCommand("Select * From Registration ", con);
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
label2.Text = dataGridView1.SelectedRows.Count.ToString();
if ((!string.IsNullOrEmpty(textBox1.Text)) && (!string.IsNullOrEmpty(label2.Text)))
{
label3.Text = (Convert.ToInt32(textBox1.Text) / Convert.ToInt32(label2.Text)).ToString("0");
}
else
{
MessageBox.Show("Select row or enter value");
}
float amount =Convert.ToInt32(label3.Text);
SqlCommand cmd2 = new SqlCommand("Update Registration set Amount= [Amount] +'" + amount + "' Where Cnic='"+cnicDataGridViewTextBoxColumn.Selected.ToString()+ "'", con);
con.Open();
cmd2.ExecuteNonQuery();
con.Close();
this.registrationTableAdapter.Fill(this.hostelmesssystemDataSet5.Registration);
}
//private void HeaderCheckBoxClick(CheckBox HCheckBox)
//{
// IsHeaderCheckBoxClicked = true;
// foreach (DataGridViewRow Row in dataGridView1.Rows)
// ((DataGridViewCheckBoxCell)Row.Cells["chk"]).Value = HCheckBox.Checked;
// dataGridView1.RefreshEdit();
// IsHeaderCheckBoxClicked = false;
////}
//private void HeaderCheckBox_MouseClick(object sender ,MouseEventArgs e)
//{
// HeaderCheckBoxClick((CheckBox)sender);
//}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
}
}
我想从gridview中选择多个男孩,并想在他的帐户中添加文本框值。如何选择多个用户并在给定记录中添加文本框值?