如何将值传递给gridview [英] how to pass value to gridview

查看:70
本文介绍了如何将值传递给gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将选定的datagridview值传递给C#.Net Windows应用程序同一页面中的另一个datagridview. /div>

这是代码段

 字符串 ID;
私有 无效 dataGridView1_CellClick(对象发​​件人,DataGridViewCellEventArgs e)
        {
            如果((e.RowIndex == -1))
            {
                 MessageBox.Show(" );
            }
            其他
            {
                尝试
                {
                    ID = dataGridView1.Rows [e.RowIndex] .Cells [ 0 ].Value.ToString();
                }
                捕获(例外)
                {
                     MessageBox.Show("  + ex.Message.ToString());
                }
             }
         } 


生成此单元格单击事件,然后尝试以下代码;只需更新要传递的单元格值的单元格值即可.

希望对您有所帮助.


您好,

如biswarup所言,在网格视图的单元格单击事件中执行此操作,当单击特定单元格时,将触发该事件,并在代码中获取该单元格值,并添加到另一个网格中

谢谢
Tapan kumar


i want to pass selected datagridview value to another datagridview in same page in C#.Net Windows Application.any one plz help me ......thanks in advance..

解决方案

Here is the code snippet

String ID;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.RowIndex == -1))
            {
                 MessageBox.Show("");
            }
            else
            {
                try
                {
                    ID = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                }
                catch(Exception ex)
                {
                     MessageBox.Show("Error:" + ex.Message.ToString());
                }
             }
         }


Generate this cell click event and try this code; just update the cell value which cell value you want to pass.

Hope it helps.


Hi,

as biswarup told, do this in the cell click event of the grid view, when a particular cell is clicked then that event will be fired and, in code get that cell value, and add to the other grid

Thanks
Tapan kumar


这篇关于如何将值传递给gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆