zoukankan
html css js c++ java
看上去没有输入焦点的只读DataGrid (WinForm)
假设已经在WinForm窗体上放置了一个名称为dataGridMsg的DataGrid,并且为窗体增加一个成员
private
DataSet DataSetMsg;
在form的Load中添加以下代码
DataSetMsg
=
new
DataSet(
"
DataSetMsg
"
);
DataTable dt
=
DataSetMsg.Tables.Add(
"
DataTableMsg
"
);
dt.Columns.Add(
"
Code
"
,
typeof
(
string
));
dt.Columns.Add(
"
Msg
"
,
typeof
(
string
));
dt.Columns.Add(
"
V
"
,
typeof
(
string
));
//
添加用于隐藏输入焦点的列
//
添加10行
for
(
int
B
=
0
;B
<
10
,B
++
)
{
DataRow dr
=
new
dt.NewRow();
dr[
"
Code
"
]
=
B.ToString().PadLeft(
4
,
'
0
'
);
dr[
"
Msg
"
]
=
"
Msg
"
+
B.ToString();
dr[
"
V
"
]
=
""
;
}
dataGridMsg.ReadOnly
=
true
;
//
指定DataGridMsg列的外观
DataView dataviewMsg
=
new
DataView(DataSetMsg.Tables[
"
DataTableMsg
"
]);
dataviewMsg.AllowDelete
=
false
;
dataviewMsg.AllowNew
=
false
;
dataGridMsg.SetDataBinding(dataviewMsg,
""
);
DataGridTableStyle ts1
=
new
DataGridTableStyle(
false
);
ts1.MappingName
=
"
DataTableMsg
"
;
ts1.AllowSorting
=
true
;
ts1.GridColumnStyles.Clear();
//
第0列--代码
DataGridTextBoxColumn CCode
=
new
DataGridTextBoxColumn();
CCode.MappingName
=
"
Code
"
;
CCode.HeaderText
=
"
代码
"
;
CCode.Width
=
100
;
CCode.Alignment
=
HorizontalAlignment.Center;
CCode.ReadOnly
=
true
;
ts1.GridColumnStyles.Add(CCode);
//
第1列-- 信息
DataGridTextBoxColumn Cmsg
=
new
DataGridTextBoxColumn();
Cmsg.MappingName
=
"
Msg
"
;
Cmsg.HeaderText
=
"
信息
"
;
Cmsg.ReadOnly
=
true
;
Cmsg.Alignment
=
HorizontalAlignment.Left;
Cmsg.Width
=
600
;
ts1.GridColumnStyles.Add(Cmsg);
//
第2列--用于隐藏输入焦点的列
DataGridTextBoxColumn CV
=
new
DataGridTextBoxColumn();
CV.MappingName
=
"
V
"
;
CV.ReadOnly
=
true
;
CV.Width
=
0
;
//
隐藏的列
ts1.GridColumnStyles.Add(CV);
dataGridMsg.TableStyles.Clear();
dataGridMsg.TableStyles.Add(ts1);
在 dataGridMsg的CurrentCellChanged 事件中添加以下代码
//
将当前列始终设置为定义的隐藏列2
dataGridMsg.CurrentCell
=
new
DataGridCell(dataGridMsg.CurrentCell.RowNumber,
2
);
查看全文
相关阅读:
Away3d学习笔记2三维世界的四个基本构件
实验报告2
实验报告
WPF基础——Application
COM技术内幕(笔记)
关于一个GetLevelDesc函数 的认知问题
UI库阶段性进展(完成文字列表,样式列表(样式列表可继承))
UI库阶段性进展
UI库阶段性进展(按钮初具雏形)
UI库阶段性进展(button在文本对齐的基础上增加文本偏移让文本位置更精准)
原文地址:https://www.cnblogs.com/bearhb/p/207546.html
最新文章
kafka配置的问题排查
Linux下用jar命令更新jar包文件
在深圳安顿下来了~
一个困扰我3天的问题解决了
PVM Group失败的原因
跨平台程序的UNICODE字符串处理方法。
在Red Hat Linux9.0下安装PVM3
Linux下iptables的配置
开始在新公司工作.
断网两天重生纪念!
热门文章
DeadLine is coming
毕业了!
Away3d 基础4 操控三维物体
Away3D 基础5 3D基本元素(2)
Away3D学习笔记33D世界的坐标系
Away3D基础53D基本元素(1)
Away3D 基础 2 视口与场景
Away3d 基础 1 对一个简单类的解释
Away3D 基础5 3D基本元素(3)
Away3d基础 3 摄像机
Copyright © 2011-2022 走看看