绑定数据源

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) == nullreturn;
   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 常用方法的更多相关文章

  1. Dev Grid拖拽移动行

    效果图 源码下载 拖拽时带行截图效果实现代码 /// <summary> /// 拖拽帮助类 /// </summary> public static class DragHe ...

  2. dev grid的一些使用

    保留选中数据,其他数据删除,不操作数据库 private void butnoremove_Click(object sender, EventArgs e) { int iSelectRowCoun ...

  3. DevExpress Grid使用checkBox选中的方法

    到官网得到消息自13.2版本后的Dev Grid中均内置了CheckBox列多选功能.在寻找答案的过程的成果进行记录. 一.13.2版本以后用法 启用多选列 对Gird中的View进行以下属性设置: ...

  4. Tkinter 的三大布局管理器 pack、grid 和 place用法汇总

    学习python的tkinter免不了要对各个组件进行位置的排放与设定,常用的布局管理器有grid,pack和place.这三种均用于同一父组件下的组件布局,但是也是有区别的,先看下他们各自的含义吧. ...

  5. DEV控件Grid显示行号

    DEV控件Grid的显示行号需要通过一个事件来设置,具体设置代码为: private void gridView1_CustomDrawRowIndicator(object sender, DevE ...

  6. dev设置子窗体的初始位置,grid控件表头的属性设置

    当在父窗体上弹出子窗体时,一般设置子窗体的初始位置是居中, //在需要展示子窗体的父窗体上写这段,注意必须设置在show方法之前Form2 f2 = new Form2(); f2.MdiParent ...

  7. 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 ...

  8. Dev GridView-Bind Detail Grid during runtime

    Here is a simple example. ASPX <%@ Page Language="C#" AutoEventWireup="true" ...

  9. dev 中 字符串转中文拼音缩写,对grid列表进行模糊匹配,grid获取焦点行,gridlookupedit控件用拼音模糊匹配下拉选项

    番外篇:. //该方法是将字符串转化为中文拼音的首写字母大写, public static string RemoveSpecialCharacters(string str){try{if (str ...

随机推荐

  1. [k8s]组件日志级别说明

    kubectl 执行命令时候 --v 调试, 也可以用作其他组件的 --v配置 参考: https://kubernetes.io/docs/user-guide/kubectl-cheatsheet ...

  2. Unity对象与Draw Calls的关系

    什么是Draw Calls? 首先我们先来了解一下,什么叫做“Draw Calls”:一个Draw Call,等于呼叫一次 DrawIndexedPrimitive (DX) or glDrawEle ...

  3. error while loading shared libraries错误解决

    在编译引用了第三方库的代码后,执行出现了以下错误 [work@xxx zktest]$ ./a.out ./a.out: error while loading shared libraries: l ...

  4. iOS之设置用户头像的圆角

    1. 显示用户头像用UIImageView实现,添加默认图片后效果如下图所示,头像显示为矩形图片. 代码实现: // ViewController.m // SetUserImage // // Cr ...

  5. H5area的热区锚点随着图片的尺寸而变化

    <area shape="rect" coords="338,308,609,589" > <img id="pic" s ...

  6. Linux之实用GDB技巧

    一.引言 在Linux下开发,肯定少不了与gdb打交道,而gdb的命令又非常多,有些是不常用的但是特殊情况下却是必须的,因此记录在此,以便翻阅 二.基本命令 前面是命令全名,在不混淆的情况下,可以简写 ...

  7. U盘工作原理(转)

    u盘工作原理 一. U盘基本工作原理 通用串行总线(Universal serial Bus)是一种快速灵活的接口, 当一个USB设备插入主机时,由于USB设备硬件本身的原因,它会使USB总线的数据信 ...

  8. 使用code::blocks搭建objective-c的IDE开发环境 支持 @interface

    网上有许多的关于 <使用code::blocks搭建objective-c的IDE开发环境>的文章. 大多是写了一个Helloworld 就结束了,今天试了试 添加了一个 @interfa ...

  9. VmWare下安装CentOS6图文安装教程

    本教程使用的liunx系统(CentOS6)下载地址:http://download.csdn.net/download/yichen01010/10016202 一 先安装VMware. 双击安装文 ...

  10. Tuning 12 manage statistics

    这个 stattistics 对解析 sql 时的优化器有很重要的作用, 优化器是基于 statistics 来进行优化的. desc dbms_stats 包也可以 desc (早期使用 analy ...