惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
V
V2EX
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
F
Full Disclosure
Y
Y Combinator Blog
V
V2EX - 技术
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
SecWiki News
SecWiki News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
量子位
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
K
Kaspersky official blog
B
Blog
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
D
Docker
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - LeeWenjie

【转发】NPAPI学习(Firefox和Chrome扩展开发 ) 【转发】NPAPI开发详解,Windows版 【转发】网易邮箱前端技术分享之javascript编码规范 【转发】揭秘Facebook 的系统架构 【转发】淘宝网架构分享总结 【转发】淘宝网采用什么技术架构来实现网站高负载的 【转发】浅析淘宝网首页信息架构的变迁 【转发】Html5 File Upload with Progress 【转载】使用JavaScript实现Motion Detection 【转发】WEB前端开发规范文档 【转发】响应式Web设计?怎样进行? 【转发】开源中最好的Web开发的资源 【原创】PDA DataGrid的滚动条事件处理 【转发】SharePoint 2010——ListData.svc故障排除 【转发】谈论 SharePoint 2010中的沙盒解决方案(Sandboxed Solution) 【原创】NET4.0在SharePoint 2010 IIS下出现导演 C#实现多语言 【转载】互联网产品开发中的“快”字诀 【转载】SHAREPOINT TimeJob定时器开发
【原创】PDA 实现DataGrid可编辑
LeeWenjie · 2012-06-13 · via 博客园 - LeeWenjie

PDA 实现DataGrid可编辑

通过继承 DataGrid 扩展实现

对ISupportInitialize 空实现,如没有,会出现异常。

在PDA设备上不能直接对DataGrid的单元格进行编辑,那么,如何实现单元格可编辑呢?我们可以用TextBox来模拟单元格,让这个TextBox一开始隐藏起来,当点击DataGrid的单元格的时候,在当前单元格的位置显示TextBox.因此我们必须要先获得当前单元格的坐标,然后显示TextBox在该坐标,并且将当前单元格的内容赋给TextBox,当用户修改了TextBox的内容并且离开该单元格时,TextBox将再次被隐藏,同时,单元格的内容被赋为TextBox的最新内容。按照以上的思路我们可以写如下代码:

 1 using System;
 2 using System.Drawing;
 3 using System.Windows.Forms;
 4 using System.ComponentModel;
 5 
 6 namespace SmartDeviceProject1
 7 {
 8     public class datagridEx :DataGrid,ISupportInitialize
 9     {
10         DataGridCell editcell = new DataGridCell();
11         Rectangle cellpos = new Rectangle();
12         TextBox txtedit = new TextBox();
13         bool isUpdateMode = false;
14         bool isEditMode = false;
15 
16         public datagridEx()
17         {
18             this.Controls.Add(txtedit);
19             txtedit.Visible = false;
20             txtedit.BringToFront();
21             txtedit.Text = "grn";
22         }
23         protected override void OnCurrentCellChanged(EventArgs e)
24         {
25             if (isUpdateMode)
26             {
27                 base.OnCurrentCellChanged(e);
28                 return;
29             }
30             DataGridCell currentcell = this.CurrentCell;
31             if (isEditMode && !this.CurrentCell.Equals(editcell))
32             {
33                 isUpdateMode = true;
34                 this[editcell.RowNumber, editcell.ColumnNumber] = txtedit.Text;
35                 this.CurrentCell = currentcell;
36                 this.Visible = true;
37                 txtedit.Visible = false;
38                 isUpdateMode = false;
39                 isEditMode = false;
40             }
41             editcell = this.CurrentCell;
42             cellpos = this.GetCellBounds(editcell.RowNumber, editcell.ColumnNumber);
43             txtedit.Left = cellpos.Left  - 1;
44             txtedit.Top = cellpos.Top  - 1;
45             txtedit.Width = cellpos.Width + 2;
46             txtedit.Height = cellpos.Height + 2;
47 
48             txtedit.Visible = true;            
49             txtedit.Text = this[editcell.RowNumber, editcell.ColumnNumber].ToString();
50 
51             txtedit.BringToFront();
52             txtedit.Focus();
53             txtedit.SelectAll();
54             isEditMode = true;
55 
56             base.OnCurrentCellChanged(e);
57         }
58 
59         #region ISupportInitialize接口实现
60         public void BeginInit()
61         {            
62         }
63         public void EndInit()
64         {
65         }
66         #endregion
67 
68     }   
69 }

当然,还可以增加回车跳转到下一单元格。