资源简介

C#_winform_DataGridView_checkbox复选框_实现单选效果

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            using (SqlConnection con = new SqlConnection())
            {
                try
                {

                    DataTable dt1 = new DataTable();
                    dt1.Columns.Add(“编号“ typeof(int));
                    dt1.Columns.Add(“姓名“ typeof(string));
                    dt1.Columns.Add(“年龄“ typeof(int));
                    dt1.Columns.Add(“性别“ typeof(string));

                    dt1.Rows.Add(1 “小王“ 20 “男“);
                    dt1.Rows.Add(2 “王小儿“ 30 “男“);
                    dt1.Rows.Add(3 “李大妈“ 40 “女“);
                    dt1.Rows.Add(4 “王大嫂“ 50 “女“);
                    dt1.Rows.Add(5 “李敏“ 60 “女“);
                    dt1.Rows.Add(6 “老李“ 70 “男“);

                    dataGridView1.DataSource = dt1;
                }
                catch { }
            }
        }
        //单击单元格(无论单击的是单元格为内容还是单元格为列头)。
        private void dataGridView1_CellClick(object sender DataGridViewCellEventArgs e)
        {
            //判断是否单击了列头  如果单击了列头e.RowIndex的值为-1;
            if (e.RowIndex >= 0)
            {
                if (e.ColumnIndex == 0)
                {
                    this.txtBianhao.Text = dataGridView1.Rows[e.RowIndex].Cells[“编号“].Value.ToString();
                    this.txtXingming.Text = dataGridView1.Rows[e.RowIndex].Cells[“姓名“].Value.ToString();
                    this.txtNianling.Text = dataGridView1.Rows[e.RowIndex].Cells[“年龄“].Value.ToString();
                    this.txtXingbie.Text = dataGridView1.Rows[e.RowIndex].Cells[“性别“].Value.ToString();
                }
            }
        }
        //MultiSelect设置为fasle,用户一次可以多选(按住ctrl键进行选择,不然只为一条)  
        // 始终在SelectedRows集合中只有一行
        //如果没有按住ctrl键进行点击选择无论MultiSelect设置为fasle或true始终选择一行
        private void button1_Click(object sender EventArgs e)
        {
            //选择的行数
            MessageBox.Show(“选择的行数:“ + dataGridView1.SelectedRows.Count.ToString());
            //选择的行
            MessageBox.Show(“选择的行[Index]:“ + dataGridView1.SelectedRows[0].Cells[0].RowIndex.ToString());
        }
        //MultiSelect设置为true遍历chexkBox选中的行
        private void button2_Click(object sender EventArgs e)
        {
            for (int p = 0; p < dataGridView1.SelectedRows.Count; p++)
            {
                MessageBox.Show(“选择了第“ + (int.Parse(dataGridView1.SelectedRows[p].Cells[0].RowIndex.ToString()) + 1).ToString() + “行“);
            }
        }
        #region
        int Las

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-01-06 15:26  C#_winform_DataGridView_checkbox复选框_实现单选效果\
     目录           0  2017-01-06 15:27  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\
     目录           0  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\
     文件         962  2013-09-14 21:02  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2.sln
     文件       28160  2013-09-14 22:50  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2.v11.suo
     文件       46592  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2.v12.suo
     文件         187  2013-09-14 21:01  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\App.config
     目录           0  2013-09-14 21:01  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\bin\
     目录           0  2013-09-14 21:07  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\bin\Debug\
     文件       14848  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe
     文件         187  2013-09-14 21:01  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe.config
     文件       28160  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.pdb
     文件       24224  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe
     文件         187  2013-09-14 21:01  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe.config
     文件         490  2013-03-18 17:00  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe.manifest
     文件        5349  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\Form1.cs
     文件       10868  2017-01-06 16:09  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\Form1.Designer.cs
     文件        7649  2017-01-06 16:09  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\Form1.resx
     目录           0  2013-09-14 21:01  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\
     目录           0  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\
     文件         865  2017-01-06 15:38  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7311  2017-01-06 15:27  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2013-09-14 21:02  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2013-09-14 21:02  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2013-09-14 21:02  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2013-09-14 21:02  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\TempPE\
     文件        2793  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.FileListAbsolute.txt
     文件         977  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.GenerateResource.Cache
     文件        2211  2017-01-06 15:27  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csprojResolveAssemblyReference.cache
     文件       14848  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.exe
     文件         180  2017-01-06 16:10  C#_winform_DataGridView_checkbox复选框_实现单选效果\DataGridView摸索\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Form1.resources
............此处省略10个文件信息

评论

共有 条评论