wince 下 Datagrid 列宽控制及Datagrid 整行选中模式实现

来源:互联网 发布:安卓版mp3编辑软件 编辑:程序博客网 时间:2024/05/01 21:09

wince下的.net 控件 Datagrid,要实现自定义各列列宽,可以使用DataGridTableStyle,控件运行时表样式.

代码如下:

//获取数据 DataSet ds = Helper.DBHelper.Query(sql);DataTable dt = ds.Tables[0]; //样式登场 DataGridTableStyle ts = new DataGridTableStyle();ts.MappingName = dt.TableName;//此处非常关键,数据表的名字不对,将无法映射成功//定义列样式DataGridColumnStyle LBarcodeColStyle =new DataGridTextBoxColumn();LBarcodeColStyle.MappingName = "Barcode";LBarcodeColStyle.HeaderText = "仓位";LBarcodeColStyle.Width = 70;ts.GridColumnStyles.Add(LBarcodeColStyle);//定义列样式DataGridColumnStyle UNameColStyle = new DataGridTextBoxColumn();UNameColStyle.MappingName = "UserName";UNameColStyle.HeaderText = "锁定人";UNameColStyle.Width = 60;ts.GridColumnStyles.Add(UNameColStyle);//定义列样式DataGridColumnStyle LockTimeColStyle = new DataGridTextBoxColumn();LockTimeColStyle.MappingName = "CreateTime";LockTimeColStyle.HeaderText = "锁定时间";LockTimeColStyle.Width = 102;ts.GridColumnStyles.Add(LockTimeColStyle);//将样式和控件绑定到一起this.dataGrid1.TableStyles.Add(ts);this.dataGrid1.DataSource = dt;


通过以上,就能实现wince下对 Datagrid的数据列宽度等属性的设置了.

另外,在wince下, Datagrid好像没办法设置SelectionMode ,自然也没有FullRowSelect 选项了.

变通一下,使用如下代码实现:

//对 Datagrid获得焦点和当前cell事件,触发执行选中整行的代码,变通实现了整行选中效果 private void dataGrid1_GotFocus(object sender, EventArgs e){int index = ((DataGrid)sender).CurrentCell.RowNumber;((DataGrid)sender).Select(index);}private void dataGrid1_CurrentCellChanged(object sender, EventArgs e){int index = ((DataGrid)sender).CurrentCell.RowNumber;((DataGrid)sender).Select(index);}


原创粉丝点击