开发者

How to copy string of a particular cell of datagrid view by double click using c# winform?

I开发者_Python百科 have this requierements that if a click a particular cell on datagrid view..it will copy the cell string and display on a textbox on the other form.

    This is my PseodoCode:

    Example:

    1.Display Datagrid View

    Name  | Family  |
    Boar  | Mamals  | 
    Snake | Reptile |  

    2.If Snake Clicked on Datagrid View.
    3.Then Copy Snake string
    4.Show Form2 then Display Snake on Textbox

Is this Possible Thanks in Regards!


Here it goes Form1 is your main form with grid called dataGridView1

private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    string x = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue.ToString();
    Form2 myForm = new Form2();
    myForm.y = x;
    myForm.ShowDialog();
}

Form2 is secondary form to display item

public partial class Form2 : Form
{
    public string y = string.Empty;
    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        textBox1.Text = y;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜