PDA

View Full Version : ویرایش مشخصات هر سطر dataGridView



aleas2
دوشنبه 06 خرداد 1392, 20:02 عصر
دوستان چطور میتونم وقتی کاربر رو یکی از فیلد ها dataGridView کلیک کرد مشخصات کامل اون سطر تو textbox نمایش بده که بتونم اون مشخصات ویرایش کنه؟

mustafa13
دوشنبه 06 خرداد 1392, 21:06 عصر
سلام
مقدار فیلد مورد نظر را به TextBox ریخته و سپس تغییر مورد نظر را اعمال کرده و سپس Update را انجام دهید
با دستور زیر می توان از DateGridView به TextBox ریخت

TextBox1.Text = dataGridViewX1.CurrentRow.Cells[1].Value.ToString();

amir200h
دوشنبه 06 خرداد 1392, 21:22 عصر
باید تو رویداد SelectionChanged دیتا گرید ویو بزاری. دقت کن که اندیس خونه های ستون از صفر شروع میشه

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{

txt_fish.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
txt_customer.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
txt_code.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
txt_price.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
txt_tedad.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
}

بعد واسه آپدیت از کد زیر استفاده کن

private void btn_zakhire_Click_1(object sender, EventArgs e)
{
frm_main.mycommand.Connection = frm_main.objconnection;
frm_main.mycommand.CommandText = "update main set foodnumber = " + txt_code.Text;
frm_main.mycommand.CommandText += " ,coustomernumber=" + txt_customer.Text + ",price = " + txt_price.Text;
frm_main.mycommand.CommandText += ", count = " + txt_tedad.Text;
frm_main.mycommand.CommandText += " where fishnumber = " + dataGridView1.CurrentRow.Cells[0].Value;
frm_main.objconnection.Open();
frm_main.mycommand.ExecuteNonQuery();
frm_main.objconnection.Close();
MessageBox.Show("ویرایش انجام شد ");
load();
}

aleas2
دوشنبه 13 خرداد 1392, 20:02 عصر
امتحان کردم خطا میده اصلا چنین متدی CurrentRow نمیشناسه