dev grid的一些使用
保留选中数据,其他数据删除,不操作数据库
private void butnoremove_Click(object sender, EventArgs e)
{
int iSelectRowCount = gridView1.SelectedRowsCount;
if (iSelectRowCount > )
{
if (MessageBox.Show("你确定只保留选中的记录吗?", "提示", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, , false) == DialogResult.Yes)
{ for (int i = ; i < gridView1.DataRowCount; i++)
{
int handle = gridView1.GetRowHandle(i);
if (!gridView1.IsRowSelected(handle))
{
gridView1.DeleteRow(handle);
i = i - ;
}
}
}
}
else
{
MessageBox.Show("请先选中要保留的记录", "提示");
}
}
行样式和格样式的设置
private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
//GridView View = sender as GridView;
//if (e.RowHandle >= 0)
//{
// string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["clores"]);
// int i = Convert.ToInt32(category);
// if (i % 2 == 0)
// {
// e.Appearance.BackColor = Color.Salmon;
// e.Appearance.BackColor2 = Color.SeaShell;
// }
//}
}
private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
GridView View = sender as GridView;
if (e.Column.FieldName == "content")
{
string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["content"]);
}
if (e.Column.FieldName == "volumeWeight" || e.Column.FieldName == "weightes")
{
e.Appearance.ForeColor = Color.YellowGreen;
}
if (e.Column.FieldName == "fweight" || e.Column.FieldName == "cfweight")
e.Appearance.ForeColor = Color.Coral;
}
}
导出excel
try
{
string path = "";
using (SaveFileDialog sfd = new SaveFileDialog())
{
sfd.Filter = "Excel文件|*.xls";
if (sfd.ShowDialog() == DialogResult.Cancel)
{
return;
}
path += sfd.FileName;
}
dvginfo.ExportToXls(path);
}
catch (Exception ex)
{
MessageBox.Show("请先关闭要替换的文件", "提示");
}
动态创建gridview,导出Excel数据
GridControl CreateGrid(List<marketinformation> pagemodel)
{
GridControl grid = new GridControl(); ;
GridView view = new GridView();
grid.ViewCollection.Add(view);
grid.MainView = view;
view.GridControl = grid; foreach (GridColumn column in gridView2.Columns)
{
DevExpress.XtraGrid.Columns.GridColumn gridColumnNumber = view.Columns.AddVisible
(column.FieldName.ToString());
gridColumnNumber.Caption = column.Caption.ToString();
gridColumnNumber.FieldName = column.FieldName.ToString();
}
grid.DataSource = pagemodel;
this.Controls.Add(grid);//重要
grid.ForceInitialize();//重要
BestColumns(view);
view.OptionsPrint.AutoWidth = false;
return grid; }
然后数据分页创建
IPrintable[] arr(List<marketinformation> data)
{
List<IPrintable> Printable=new List<IPrintable>();
int PageIndex=;
int PageSize=;
int CurrentIndex=;
int TotalCount=data.Count;
for(PageIndex=;CurrentIndex<TotalCount;PageIndex++)
{
var PageData = data.Skip(PageIndex*PageSize).Take(PageSize).ToList();
Printable.Add(CreateGrid(PageData));
CurrentIndex=(PageIndex+)*PageSize;
}
return Printable.ToArray(); }
最后数据多的时候自动列宽或假死,可以循环固定列宽,也可以写字段名
void BestColumns(GridView view)
{
if (chkeds.Checked)
{
view.OptionsView.ColumnAutoWidth = false;
foreach (GridColumn column in view.Columns)
{
if (column.Visible)
{
switch (column.FieldName.ToString())
{
case "caccount":
view.Columns["caccount"].Width = ;
break;
case "cunitname":
view.Columns["cunitname"].Width = ;
break;
case "ddate":
view.Columns["ddate"].Width = ;
break;
case "cemskind":
view.Columns["cemskind"].Width = ;
break;
case "cnum":
view.Columns["cnum"].Width = ;
break;
case "dsysdate":
view.Columns["dsysdate"].Width = ;
break;
default:
view.Columns[column.FieldName].Width = ;
break;
}
}
}
}
else
{
view.OptionsView.ColumnAutoWidth = true;
foreach (GridColumn column in view.Columns)
{
if (column.Visible)
{
view.Columns[column.FieldName].Width = ;
}
}
} }
按钮上出现提示框
this.toolTipController1.AutoPopDelay = ;
ToolTipControllerShowEventArgs args = this.toolTipController1.CreateShowArgs();
this.toolTipController1.SetToolTip(this.button1, "请选择一条记录!");
this.toolTipController1.SetTitle(this.button1, "提示");
this.toolTipController1.SetToolTipIconType(this.button1,
DevExpress.Utils.ToolTipIconType.Exclamation);
this.toolTipController1.ShowBeak = true;
this.toolTipController1.ShowShadow = true;
this.toolTipController1.Rounded = true;
this.toolTipController1.ShowHint("请选择一条记录!", "提示");
args.ToolTip = "请选择一条记录!";
args.Title = "提示";
return;
用的控件是toolTipController
没数据控件显示文本
private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
{
if ((sender as GridView).RowCount == )
{
int width = ;
int height = ;
int font_size = ;
string str = "* 没有查询到数据!\r\n* no data found!";
Font f = new Font("微软雅黑", font_size, FontStyle.Bold);
Rectangle r = new Rectangle((e.Bounds.Width - width) / , (e.Bounds.Height - height) / , width, height);
e.Graphics.DrawString(str, f, Brushes.LightBlue, r);
e.Handled = true;
}
}
dev grid的一些使用的更多相关文章
- Dev Grid拖拽移动行
效果图 源码下载 拖拽时带行截图效果实现代码 /// <summary> /// 拖拽帮助类 /// </summary> public static class DragHe ...
- dev grid 常用方法
绑定数据源 public void Data(){DataTable td = new DataTable();DataRow row = td.NewRow();foreach (GridColum ...
- DevExpress Grid使用checkBox选中的方法
到官网得到消息自13.2版本后的Dev Grid中均内置了CheckBox列多选功能.在寻找答案的过程的成果进行记录. 一.13.2版本以后用法 启用多选列 对Gird中的View进行以下属性设置: ...
- 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 ...
- dev中如何对combox下拉框设置可消除属性以及ASPxGridView中金额,数量的显示,以及总计、grid中某行值
下拉框属性关键:IncrementalFilteringMode="StartsWith" DropDownStyle="DropDown" ASPxGridV ...
随机推荐
- mysql:启动服务时遇到的问题
1.cmd命令: 在切换路径时,如果要切到另外一个磁盘,比如从C盘切到E盘,命令如下: cd /d 你要切换的路径 2.错误:“服务名无效” 问题原因:mysql服务没有安装.(参考:https:// ...
- java调用exe,及调用bat不成功的解决办法
开门见山的说,文件目录如下 想调用123.exe,但是尝试了几次调用不到,然后写了个bat.初始内容如下 @echo off D: cd test "123.exe" 双击可以运行 ...
- No hash for parcel CDH-XXX.parcel.torrent
在安装 CDH 时,到 Install Parcels 这一步,分发 Parcels 一直过不去,界面一直报 Failure due to stall on seeded torrent,查看日志一直 ...
- 查看MySQL 连接信息--连接空闲时间及正在执行的SQL
MySQL 客户端与MySQL server建立连接后,就可以执行SQL语句了. 如何查看一个连接上是否正在执行SQL语句,或者连接是否处于空闲呢? 下面我们做下测试. 1.查看连接的空闲时间 首先看 ...
- python git 基础操作
模块安装 pip install gitpython 基本用法 1. 初始化 from git import Repo Repo.init('/data/test2') # 创建一个git文件夹 # ...
- Repeater, DataList, 和GridView的区别及使用
从对象层次图可以看出,Repeater是最轻最小的控件,它仅仅继承了基本控件的功能,包括ID属性.子控件集合等.另一方面,DataList和DataGrid则继承了WebControl功能,包括样式和 ...
- [Ubuntu]18安装百度网盘
1.下载客户端 下载地址: 选择linux版本,我选择的是deb格式,下载就可以了. 2.安装 进入下载目录,点击右键,选择在终端打开. 之后输入 以下代码愉快的安装就好了 注意:dpkg后面跟的文 ...
- Pytorch-拼接与拆分
引言 本篇介绍tensor的拼接与拆分. 拼接与拆分 cat stack split chunk cat numpy中使用concat,在pytorch中使用更加简写的 cat 完成一个拼接 两个向量 ...
- View的介绍和运用 && FlexBox布局
开始我们今天的项目学习啦~~~~~~ 1> 第一步当然是创建项目啦: 进入终端: 创建ViewDemo项目 命令如下啦,你看懂了对吧...嘻嘻!!! 2>View的介绍和运用 项目安装创建 ...
- Qt在控制台输出中文的解决办法(转载)
转载网址:https://blog.csdn.net/qq_22512533/article/details/75408984 按下快捷键Win+R,输入regedit打开注册变编辑器,依次找到 HK ...