简体   繁体   English

如何使用c#winform双击复制datagrid视图的特定单元格的字符串?

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

I 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. 我有这样的要求,如果单击datagrid view ..上的特定单元格,它将复制该单元格字符串并显示在另一种形式的文本框中。

    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 Form1是您的主要表单,带有名为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 Form2是显示项目的辅助表格

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM