您的位置:首页 > 编程语言 > C#

C#Winform基础 datagridview控件一选选一整行的效果实现时,取消第一行默认被选取的副效果

2016-10-18 23:09 776 查看

 镇场诗:
    清心感悟智慧语,不着世间名与利。学水处下纳百川,舍尽贡高我慢意。
    学有小成返哺根,愿铸一良心博客。诚心于此写经验,愿见文者得启发。
——————————————————————————————————————————

 

1 UI

 

 

2 code

 

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Xml.Linq;
11
12 namespace WindowsFormsApplication3
13 {
14     public partial class Form1 : Form
15     {
16         public Form1()
17         {
18             InitializeComponent();
19         }
20
21         List<User> datas = new List<User>();
22
23         private void Form1_Load(object sender, EventArgs e)
24         {
25             LoadXmlFile();
26
27
28             ///////////////////////////////////////////////////
29             //取消第一行默认被选中的负效果
30             dataGridView1.SelectedRows[0].Selected = false;
31             ///////////////////////////////////////////////////
32
33         }
34
35         private void LoadXmlFile()
36         {
37             //form 窗体在加载的时候,读取xml文件
38             XDocument xmlFile = XDocument.Load("1.xml");
39             XElement root = xmlFile.Root;
40
41             foreach (var item in root.Elements())
42             {
43                 datas.Add(new User() { ShengHao = item.Element("ShengHao").Value, Password = item.Element("Password").Value });
44             }
45
46             //将list数据与datagridview绑定
47             dataGridView1.DataSource = datas;
48
49         }
50     }
51 }

 

 

3 show

 

注:舍名利 喜欢看儒释道的书籍,所以举的例子不是普通的例子,但效果都是一样的,还望能看得过去。

 

——————————————————————————————————————————
博文的精髓,在技术部分,更在镇场一诗。版本:VS2015 系统:Windows 7
C#是优秀的语言,值得努力学习。我是跟随 传智播客\黑马 .Net视频教程学习的。
如果博文的内容有可以改进的地方,甚至有错误的地方,请留下评论,我一定努力改正,争取铸成一个良心博客。
注:此文仅作为科研学习,如果我无意中侵犯了您的权益,请务必及时告知,我会做出改正。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: