dev grid 常用方法
绑定数据源
public void Data()
{
DataTable td = new DataTable();
DataRow row = td.NewRow();
foreach (GridColumn item in gridView1.Columns)
{
DataColumn it = new DataColumn(item.FieldName, typeof(String));
if (item.FieldName == "check")//添加复选框
{
td.Columns.Add(item.FieldName, Type.GetType("System.Boolean"));
td.Columns[item.FieldName].DefaultValue = Boolean.FalseString;
continue;
}
td.Columns.Add(it);
}
gridControl1.DataSource = td;
}
//重要

列标题字体设置
Appearences》HeaderPanel
1、获取选中行的某列的值:object ojb =GridView1.getrowcellvalue(GridView1.focusedrowhandle,"列名");
获取选中行的某列的值
this.gridView1.GetRowCellValue(0, gridView1.Columns["StorkCode"]);
//赋值
this.gridView1.SetRowCellValue(i, gridView1.Columns["jianshu"], gdjianshu.ToString());
2、设置标头居中,只需要设置Views-->Appearance-->HeaderPanel-->TextOptions.HAlignment=Center。内容居中设置:Columns-->AppearanceCell-->TextOptions.HAlignment=Center。上图第一列设置了内容居中。
3、设置Gridview控件,列头不可排序
this.gridDataDetail.gridView1.OptionsCustomization.AllowSort = false;
4、使Gridview控件,失去选中焦点
this.gridData.gridView1.FocusedRowHandle = -1
5、判断Gridview是否选中了数据
int index= this.gridData.gridView1.GetFocusedDataSourceRowIndex() ;
如果index小于0,证明没有选中行,否则就选中了行数据
6、获取选中Gridview的行数据
DataRow vCurrenRow = this.gridData.gridView1.GetFocusedDataRow();
7、删除选中Gridview行数据
this.gridDataDetail.gridView1.DeleteRow(this.gridDataDetail.gridView1.FocusedRowHandle);
8、Gridview新增一条编辑行
DataRow vDetailRow = this.DataDetailSourceTable.Rows.Add(); //这是新增加了一行
vDetailRow["primary_key"] = ""; primary_key为数据库绑定到Gridview中的字段,后面可以对其进行赋值。
9、获取GridView中所有的选中的行号
int[] iRowId = this.gridData.gridView1.GetSelectedRows();
在表格添加一列按钮
在column properties-->buttons--->将属性kind选为Glyph,然后将Caption设为把ButtonEdit的TextEditStyle设为HideTextEditor然后Button,第一个button的Caption写GO,Kind设为Glyph
在Gridview的OptionCustomization里面,有个属性叫"AllowColumnMoving",把这个关闭,就不会显示Column Chooser的菜单了。
//选中行的下标
int index = this.gridView1.FocusedRowHandle;
//判断是否为回车
if (e.KeyChar == Keys.Enter.GetHashCode())
{
//视图内是否有数据,并且当前下标是否在最后一行
if (gridView1.Columns.View.RowCount != 0 && index < gridView1.Columns.View.RowCount - 1)
{
//如果大于0就从下标行开始
if (index > 0)
{
//TO DO
}
}
else {
// SubjectQuotaRowAdd();
}
}
//这是我写的 回车代表新建 也能够代替Tab跳格键 我现在只能做出回车焦点定位到某行 而不能定位到某行的某单元
4、获取RadioGroup上选择的是哪一个,代码如下:
private void radioGroup1_SelectedIndexChanged(object sender, EventArgs e)
{
if (radioGroup1.SelectedIndex == 1)
{
MessageBox.Show("未发送");
}
if (radioGroup1.SelectedIndex == 0)
{
MessageBox.Show("已发送");
}
if (radioGroup1.SelectedIndex == 2)
{
MessageBox.Show("发送失败");
}
}
在gridview的CustomDrawCell事件中,添加如下代码,则可实现行数据的颜色控制。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
if (gvData.GetDataRow(e.RowHandle) == null) return; if (gvData.GetDataRow(e.RowHandle)["列名"].ToString()=="1" ) {//该行数据的该列的值为1时,其背景色为gray e.Appearance.BackColor = Color.Gray; } else { e.Appearance.BackColor = Color.Blue; } if (e.RowHandle == gvData.FocusedRowHandle) { e.Appearance.ForeColor = Color.White; e.Appearance.BackColor = Color.RoyalBlue; } |
private void gridView2_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { if(e.RowHandle == 2 && e.Column.FieldName == "NAME") { e.Appearance.ForeColor = Color.Red; } }知道DevExpress XtraGrid是如何定位和查找指定列显示值的行吗?注意是列的实显示值,而不是关联数据源列值。
下面将给出两个查找实例的代码,供大家一起来分享:
using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Columns; // ... string searchText = "Japan"; // obtaining the focused view ColumnView view = (ColumnView)gridControl1.FocusedView; // obtaining the column bound to the Country field GridColumn column = view.Columns["Country"]; if(column != null) { // locating the row //如果用数据源中的列值,请用ColumnView.LocateByValue int rhFound = view.LocateByDisplayText(view.FocusedRowHandle + 1, column, searchText); // focusing the cell if(rhFound != GridControl.InvalidRowHandle) { view.FocusedRowHandle = rhFound; view.FocusedColumn = column; } }
DevExpress.XtraGrid.Views.Base.ColumnView view = gridControl1.MainView as DevExpress.XtraGrid.Views.Base.ColumnView; view.BeginUpdate(); try { int rowHandle = 0; DevExpress.XtraGrid.Columns.GridColumn col = view.Columns["Category"]; while(true) { // locating the next row rowHandle = view.LocateByValue(rowHandle, col, "SPORTS"); // exiting the loop if no row is found if (rowHandle == DevExpress.XtraGrid.GridControl.InvalidRowHandle) break; // perform specific operations on the row found here // ... rowHandle++; } } finally { view.EndUpdate(); }
dev grid 常用方法的更多相关文章
- Dev Grid拖拽移动行
效果图 源码下载 拖拽时带行截图效果实现代码 /// <summary> /// 拖拽帮助类 /// </summary> public static class DragHe ...
- dev grid的一些使用
保留选中数据,其他数据删除,不操作数据库 private void butnoremove_Click(object sender, EventArgs e) { int iSelectRowCoun ...
- DevExpress Grid使用checkBox选中的方法
到官网得到消息自13.2版本后的Dev Grid中均内置了CheckBox列多选功能.在寻找答案的过程的成果进行记录. 一.13.2版本以后用法 启用多选列 对Gird中的View进行以下属性设置: ...
- Tkinter 的三大布局管理器 pack、grid 和 place用法汇总
学习python的tkinter免不了要对各个组件进行位置的排放与设定,常用的布局管理器有grid,pack和place.这三种均用于同一父组件下的组件布局,但是也是有区别的,先看下他们各自的含义吧. ...
- DEV控件Grid显示行号
DEV控件Grid的显示行号需要通过一个事件来设置,具体设置代码为: private void gridView1_CustomDrawRowIndicator(object sender, DevE ...
- dev设置子窗体的初始位置,grid控件表头的属性设置
当在父窗体上弹出子窗体时,一般设置子窗体的初始位置是居中, //在需要展示子窗体的父窗体上写这段,注意必须设置在show方法之前Form2 f2 = new Form2(); f2.MdiParent ...
- iphone Dev 开发实例9:Create Grid Layout Using UICollectionView in iOS 6
In this tutorial, we will build a simple app to display a collection of recipe photos in grid layout ...
- Dev GridView-Bind Detail Grid during runtime
Here is a simple example. ASPX <%@ Page Language="C#" AutoEventWireup="true" ...
- dev 中 字符串转中文拼音缩写,对grid列表进行模糊匹配,grid获取焦点行,gridlookupedit控件用拼音模糊匹配下拉选项
番外篇:. //该方法是将字符串转化为中文拼音的首写字母大写, public static string RemoveSpecialCharacters(string str){try{if (str ...
随机推荐
- Java并发编程(九):拓展
java多线程死锁理解 Java多线程并发最佳实践 Spring与线程安全 HashMap与ConcurrentHashMap 关于java集合类HashMap的理解 , 数据结构之 ...
- [svc]rsyslog及logrotate小结
[root@node1 logrotate.d]# ls dracut haproxy httpd mcelog nginx ppp psacct syslog yum yum install ngi ...
- [Delphi] 常用字符集简介
转载 http://www.cnblogs.com/yangyxd/articles/4778483.html 字符集 ANSI (ASCII)美国信息互换标准编码 GB 2312信息交换用汉字编码字 ...
- pycharm-community-3.1.1.tar.gz下载
国外服务器着实慢, 下载地址:http://yun.baidu.com/share/link?shareid=2521912381&uk=3020189984
- quick-cocos2d-x的热更新机制实现
quick-cocos2d-x的热更新机制实现 0 依赖 这里说的热更新,指的是客户端的更新. 大致的流程是,客户端在启动后访问更新api,根据更新api的反馈,下载更新资源,然后使用新的资源启动客户 ...
- 2PC&3PC
在分布式系统中,每一个机器节点虽然都能够明确地知道自己在进行实物操作过程中的结果是成功或失败,但却无法直接获取到其他分布式节点的操作结果.为了保持实物处理的ACID特性,就需要引入一个称为" ...
- C. Beautiful Numbers
C. Beautiful Numbers Time Limit : 4000/2000ms (Java/Other) Memory Limit : 524288/262144K (Java/Oth ...
- [Python基础]Python文件处理小结
1. 文件的打开与关闭 <1>打开文件 在python,使用open函数,可以打开一个已经存在的文件,或者创建一个新文件 open(文件名,访问模式) 示例如下: f = open('te ...
- Storm学习笔记——简介
1. 简介 流式计算的历史 早在7.8年前诸如UC伯克利.斯坦福等大学就开始了对流式数据处理的研究,但是由于更多的关注于金融行业的业务场景或者互联网流量监控的业务场景,以及当时互联网数据场景的限制,造 ...
- spring-boot启动注解@EnableAutoConfiguration
springboot很多依赖插件是只要有依赖,就会读取相关配置,如果读取不到,就会使用默认的,可能会报错,但是又在项目中不好排除就可以使用 @EnableAutoConfiguration 注解.启动 ...