保留选中数据,其他数据删除,不操作数据库

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的一些使用的更多相关文章

  1. Dev Grid拖拽移动行

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

  2. dev grid 常用方法

    绑定数据源 public void Data(){DataTable td = new DataTable();DataRow row = td.NewRow();foreach (GridColum ...

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

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

  4. DEV控件Grid显示行号

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

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

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

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

  7. Dev GridView-Bind Detail Grid during runtime

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

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

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

  9. dev中如何对combox下拉框设置可消除属性以及ASPxGridView中金额,数量的显示,以及总计、grid中某行值

    下拉框属性关键:IncrementalFilteringMode="StartsWith" DropDownStyle="DropDown" ASPxGridV ...

随机推荐

  1. Beta冲刺(2/5)

    队名:new game 组长博客 作业博客 组员情况 鲍子涵(队长) 过去两天完成了哪些任务 验收游戏素材 学习Unity 2D Animation系统 基本做完了人物的各个动画 接下来的计划 冲击E ...

  2. python Telnet通讯

    摘要: python中telnetlib模块的使用: http://blog.csdn.net/five3/article/details/8099997 python实现telnet: http:/ ...

  3. 2965 -- The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27893 ...

  4. javascript 数据分组

    一.静态数据 [ {"id":"1001","name":"值1","value":"11 ...

  5. SdCardUtils

    import android.os.Environment; import android.os.StatFs; public class SdCardUtils { public static bo ...

  6. Java堆大小[z]

    JVM中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系统的可用虚拟内存限制:系统的可用物理内存限制. 32位系统下,一般限制在1.5G~2G:64为操作系统对内存 ...

  7. 一个简单的C共享库的创建及Python调用此库的方法

    /********************************************************************* * Author  : Samson * Date    ...

  8. Spring-Kafka —— KafkaListener手动启动和停止

    一.KafkaListener消费 /** * 手动提交监听. * * @param record 消息记录 * @param ack 确认实例 */ @Override @KafkaListener ...

  9. nginx+gunicorn拓扑

    加装Nginx是否有必要 Nginx作为代理服务器,监听来自外部的80端口的请求:而Gunicorn负责监听本地机8000端口的请求.Nginx会把来自外部的请求转发给Gunicorn处理,接收到响应 ...

  10. vue-router跳转相同路径报错

    import Vue from 'vue' import Router from 'vue-router' // hack router push callback const originalPus ...