zoukankan
html css js c++ java
我涉及的DataGrid使用 一
1、绑定数据源
/***1DGrid**/
#region
/***1DGrid**/
/**/
///
<summary>
///
查询数据库,提取试题数据
///
</summary>
private
void
addDataGridData()
{
try
{
AcceGetData data
=
new
AcceGetData();
DataSet ds
=
data.GetEDataSet(p_mdbFullName,p_eTableName);
//
this.dataGrid1.SetDataBinding(ds,"");
this
.dataGrid1.DataSource
=
ds;
this
.dataGrid1.DataMember
=
ds.Tables[
0
].TableName;
//
中文列名
DGStyle (ds.Tables[
0
]);
}
catch
(Exception err)
{
MessageBox.Show(
this
,err.Message.ToString(),
"
提取1数据
"
,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
2、设置中文列名显示:
/*11中文列名*/
#region
/*11中文列名*/
private
void
DGStyle (DataTable tab)
{
ArrayList myArray
=
new
ArrayList();
//
13
myArray.Add(
"
序号
"
);
myArray.Add(
"
年份
"
);
myArray.Add(
"
地区
"
);
……
myArray.Add(
"
说明
"
);
DataGridTableStyle tableStyle
=
new
DataGridTableStyle();
if
(dataGrid1.TableStyles.Count
==
0
)
{
tableStyle.MappingName
=
tab.TableName;
//
设定数据源的表名
tab.DefaultView.AllowNew
=
true
;
tableStyle.RowHeadersVisible
=
true
;
tableStyle.RowHeaderWidth
=
10
;
/
/
设定表格 表头,奇数列等的颜色 tableStyle.AlternatingBackColor
=
Color.Lavender;
tableStyle.HeaderBackColor
=
Color.LightSteelBlue;
tableStyle.SelectionBackColor
=
Color.CadetBlue;
for
(
int
i
=
0
;i
<
tab.Columns.Count;i
++
)
{
DataGridTextBoxColumn TxtCol
=
new
DataGridTextBoxColumn();
TxtCol
=
new
DataGridTextBoxColumn();
TxtCol.MappingName
=
tab.Columns[i].ColumnName ;
//
数据源的列名
TxtCol.HeaderText
=
myArray [i].ToString() ;
//
DataGrid上的列名
TxtCol.ReadOnly
=
false
;
//
设置列属性的可修改性
//
TxtCol.TextBox.DoubleClick
+=
new
EventHandler(TextBoxDoubleClickHandler);
//
//
设置列宽
if
(i
==
8
||
i
==
9
)
{
TxtCol.Width
=
0
;
}
else
{
TxtCol.Width
=
60
;
}
TxtCol.NullText
=
"
未设定
"
;
//
该单元数据在数据库中值为NULL时的显示文本
tableStyle.GridColumnStyles.Add(TxtCol);
//
添加到样式列表中
}
}
dataGrid1.TableStyles.Add (tableStyle);
}
private
void
TextBoxDoubleClickHandler(
object
sender, EventArgs e)
{
//
记忆当前行号
currentERowIndex
=
this
.dataGrid1.CurrentCell.RowNumber;
GetSomeFileName(dataGrid1,currentERowIndex);
dataGrid1.Select(currentERowIndex);
}
#endregion
查看全文
相关阅读:
51nod 1416 两点 dfs
Codeforces Round #424 (Div. 2) A-C
Codeforces Round #423 (Div. 2) A-C
Codeforces Round #422 (Div. 2) A-C
HDU 6077 Time To Get Up 模拟
51nod 1381 硬币游戏 概率
51nod 1100 斜率最大 计算几何
hihocoder 1287 : 数论一·Miller-Rabin质数测试 大质数判定
字典树
数论
原文地址:https://www.cnblogs.com/flashicp/p/773927.html
最新文章
html+css :时间轴布局
SpringMVC拦截静态资源的问题
移动端接口碰到了服务器无法解析ios端传回?
前端开发案例:【flex】完美页脚
福利月|这个月你想要什么书
前端开发:Vue写一个购物车
课工场专业线上答疑【有问必答】学员疑问汇总
学前段好还是后端 超炫的canvas【粒子旋涡】密集恐惧症者勿进
codeforces div.1 A
NOIP 2015提高组复赛
热门文章
codeforces D
特殊密码锁
苹果和虫子2
套题T6
RMQ和LCA
套题T5//各种树
套题T4
结构体
51nod 1073 约瑟夫环
51nod 1534 棋子游戏 博弈
Copyright © 2011-2022 走看看