.net C#Windows应用程序,用于数据网格视图选择功能 [英] .net C# windows application for data grid view select function

查看:80
本文介绍了.net C#Windows应用程序,用于数据网格视图选择功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我是C#.net Windows应用程序的新手.我正在使用数据网格视图(dgv1),在dgv1中,必须通过select函数放置,我可以选择要打印的记录
有什么可以帮我编码相同的
请帮忙

谢谢与问候
为此,您可以在属性中提供复选框列?转到属性并添加复选框列.完成.添加按钮并放置以下代码.

void select_btnClick(object sender, EventArgs e)
        {
            try {
                if(dataGridView1.SelectedRows.Count>0)
                {
                    foreach(DataGridViewRow row in dataGridView1.Rows)
                    {
                        DataGridViewCheckBoxCell  cbc = (DataGridViewCheckBoxCell ) row.Cells[0];
                        cbc.TrueValue=true;
                        bool myvalue=(bool)cbc.Value;
                        bool myvalue1=(bool)cbc.TrueValue;
                        if(myvalue==myvalue1)
                        {
                            int index=row.Index;//you will get the selected index here
                           //do the operation here
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }





希望对您有帮助!


Hi All,
I m new to C# .net windows application. I m using Data grid view(dgv1),in dgv1 I have to put select function through I can select record for print
can any help me code for the same
Please help

Thanks & Regards
Indrajit

解决方案

for this you can provide checkbox column right??go to properties and add checkbox column..and you are done..add a button and place following code.

void select_btnClick(object sender, EventArgs e)
        {
            try {
                if(dataGridView1.SelectedRows.Count>0)
                {
                    foreach(DataGridViewRow row in dataGridView1.Rows)
                    {
                        DataGridViewCheckBoxCell  cbc = (DataGridViewCheckBoxCell ) row.Cells[0];
                        cbc.TrueValue=true;
                        bool myvalue=(bool)cbc.Value;
                        bool myvalue1=(bool)cbc.TrueValue;
                        if(myvalue==myvalue1)
                        {
                            int index=row.Index;//you will get the selected index here
                           //do the operation here
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }





hope it helps!!


这篇关于.net C#Windows应用程序,用于数据网格视图选择功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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