ویرایش سلولهای DataGridView فرم اول در فرم دوم
یک برنامه ویندوزی با دو فرم ایجاد کنید (Form1 و form2).
بر روی فرم اول یک کنترل DatagridView قرار دهید و خاصیت SelectionMode آن را به FullRowSelect تغییر دهید.
بر روی فرم دوم دو کنترل TextBox بگذارید.
در فرم اول برای رویدادهای Form_Ativated و Form1_Load و dataGridView1_CellMouseDoubleClick به ترتیب کدهای زیر را بنویسید :
using System; using System.Windows.Forms; namespace WindowsFormsApplication7 { public partial class Form1 : Form { public string New_Name { get; set; } public string New_Family { get; set; } public bool Flag { get; set; } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.Flag = false; this.dataGridView1.Rows.Add("سیاوش", "ابراهیمی"); this.dataGridView1.Rows.Add("یونس", "ابراهیمی"); } private void Form1_Activated(object sender, EventArgs e) { if (Flag == true) { this.dataGridView1.CurrentRow.Cells[0].Value = this.New_Name; this.dataGridView1.CurrentRow.Cells[1].Value = this.New_Family; this.Flag = false; } } private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { Form2 form2 = new Form2(); form2.Name = dataGridView1.CurrentRow.Cells[0].Value.ToString(); form2.Family = dataGridView1.CurrentRow.Cells[1].Value.ToString(); form2.form1_reference = this; form2.ShowDialog(); } } }
و برای رویدادهای Load و FormClosing فرم دوم نیز کدهای زیر را بنویسید :
using System; using System.Windows.Forms; namespace WindowsFormsApplication7 { public partial class Form2 : Form { public string Name { get; set; } public string Family { get; set; } public Form1 form1_reference { get; set; } public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { this.textBox1.Text = this.Name; this.textBox2.Text = this.Family; } private void Form2_FormClosing(object sender, FormClosingEventArgs e) { this.form1_reference.New_Name = this.textBox1.Text; this.form1_reference.New_Family = this.textBox2.Text; this.form1_reference.Flag = true; } } }
حال برنامه را اجرا کرده و بر روی یک سطر دوبار کلیک نمایید و یکی از سلولها را ویرایش کنید :
سلام
من اینو نمی بینم تو wpf چی بجاش اومد.
dataGridView1.Rows
سلام
من میخام مقدارهایی ک تو دیتا گرید ویو هست تو combo box نشون بدم.
تو text box میتونم اما combo نمیشه راهنمایی کنید لطفا