Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 4 của 4
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Hiển thị dữ liệu từ datagridview sang textbox !

    Mình có 1 Winform hiển thị như thế này :


    Mình muốn hiển thị đoạn text ở column Folder sang textbox ở form 2 khi mình nhấn nút edit thì mình phải làm thế nào, xin hãy hướng dẫn mình. Đây là code nut edit với button của mình :
    Mã:
     private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                if (dataGridView1.Columns[e.ColumnIndex].Name == "Delete")
                {
                    if (MessageBox.Show("Are you sure to delete?", "Deleting...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        dataGridView1.Rows.RemoveAt(e.RowIndex);
                        dataGridView1.ClearSelection();
                    }
    
                }
                else if (dataGridView1.Columns[e.ColumnIndex].Name == "Edit")
                {
                    Form3 form = new Form3();
                    form.Show();
                    Hide();
                }
            }

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Bạn viết thêm ở Form3 cho phép truyền giá trị qua là được.

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Trích dẫn Gửi bởi ductuyen2511
    Mình có 1 Winform hiển thị như thế này :


    Mình muốn hiển thị đoạn text ở column Folder sang textbox ở form 2 khi mình nhấn nút edit thì mình phải làm thế nào, xin hãy hướng dẫn mình. Đây là code nut edit với button của mình :
    Mã:
     private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                if (dataGridView1.Columns[e.ColumnIndex].Name == "Delete")
                {
                    if (MessageBox.Show("Are you sure to delete?", "Deleting...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        dataGridView1.Rows.RemoveAt(e.RowIndex);
                        dataGridView1.ClearSelection();
                    }
    
                }
                else if (dataGridView1.Columns[e.ColumnIndex].Name == "Edit")
                {
                    Form3 form = new Form3();
                    form.Show();
                    Hide();
                }
            }
    Bạn tạo Constructor của form 3 có tham số truyền vào. rồi lúc Form3 form = new Form3(parameter); parameter bạn get từ column folder mà bạn click.

  4. #4
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Bạn có thể làm cách sau:
    - khai báo 1 biến string dạng public static ở form3
    vd:
    Mã:
    public static string abc;
    khi gọi form3 thì
    Mã:
     Form3 form = new Form3();
                    form.abc = dataGridView1.CurrnetRow.Cells["Folder"].value.ToString().Trim();//cái này là lấy dòng hiện tại của cột Folder mà con trỏ chuột đang trỏ vào
                    form.Show();
                    Hide();
    rồi khi load form3 bạn gán cái giá trị này vào TextBox của form3 là được
    vd:
    Mã:
    txtCaigido.Text = abc;

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •