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 ...
随机推荐
- atitit.软件设计模式大的总结attialx总结
atitit.软件设计模式大的总结attialx总结 1. 设计模式的历史3 2. 设计模式的数量(253个)3 3. 设计模式的结构4 3.1. 应用场景and条件Context4 3.2. Pro ...
- Android收起虚拟键盘
关于收起虚拟键盘,网上能找到的大多是这个: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_M ...
- C# 执行多条SQL更新语句,实现数据库事务
class Program { class Result<T> { public T data; public string Message; public bool Success; p ...
- python之字符串处理
#!/usr/bin/env python #-*- coding:utf-8 -*- ############################ #File Name: strformat.py #A ...
- linux命令之高级使用 du
du命令:disk usage,顾名思义,是关于目录使用情况的,它的作用就是计算目录大小的. 1. 想看当前目录下所有目录以及子目录的大小: # du -h . “.”代表当前目录下.也可以换成一个明 ...
- 在Linux下搭建git服务器
http://www.cnblogs.com/dee0912/p/5815267.html 步骤很详细,很受用
- 如何设置python的编码格式为utf-8
重装了系统(ubuntu 14.04)原来正常可用的OpenERP项目在切换到开发者模式的时候报错: UnicodeDecodeError: 'ascii' codec can't decode by ...
- quick-cocos2d-x的热更新机制实现
quick-cocos2d-x的热更新机制实现 0 依赖 这里说的热更新,指的是客户端的更新. 大致的流程是,客户端在启动后访问更新api,根据更新api的反馈,下载更新资源,然后使用新的资源启动客户 ...
- Python爬虫框架--pyspider初体验
之前接触scrapy本来是想也许scrapy能够让我的爬虫更快,但是也许是我没有掌握scrapy的要领,所以爬虫运行起来并没有我想象的那么快,看这篇文章就是之前使用scrapy的写得爬虫.然后昨天我又 ...
- android mvp设计模式
什么是MVP MVP,全称 Model-View-Presenter.要说MVP那就不得不说一说它的前辈——MVC(Model-View-Controller,模型-视图-控制器). View:对应于 ...