C#、devExpress 的 给bandedGrid加菜单功能 :复制、粘贴的例子

CopyFromGrid

PasteToGrid

PasteNewRowsToGrid


       private void mnuPaste_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
//if(bandedGridView1.GetSelectedRows)
int[] iSelRowIndexs=bandedGridView1.GetSelectedRows();
if(iSelRowIndexs==null || iSelRowIndexs.Length==0)
{
Common.DisplayMsg(this.Text,"先请选择需要范围");
}else
{
string sFieldName = bandedGridView1.FocusedColumn.FieldName;
if(sFieldName !=null)
{
if (sFieldName == "Discount" || sFieldName == "ProjectRating")
PasteToGrid(bandedGridView1, iSelRowIndexs[0], iSelRowIndexs.Length, sFieldName);
}
}
this.Cursor = Cursors.Default;
} private void CopyFromGrid(DevExpress.XtraGrid.Views.BandedGrid.BandedGridView bandedGrid)
{
int[] iSelRowIndexs = bandedGridView1.GetSelectedRows();
if(iSelRowIndexs ==null || iSelRowIndexs.Length==0)
{
Common.DisplayMsg(this.Text,"请先选择需要复制的内容");
return;
} DevExpress.XtraGrid.Columns.GridColumn[] gcs = null; Clipboard.Clear();
StringBuilder sb = new StringBuilder();
int iRow = 0;
for (int iTemp = 0; iTemp < iSelRowIndexs.Length; iTemp++)
{
iRow = iSelRowIndexs[iTemp];
gcs = bandedGridView1.GetSelectedCells(iRow);
foreach(DevExpress.XtraGrid.Columns.GridColumn gc in gcs)
{
sb.Append(bandedGridView1.GetRowCellValue(iRow, gc)); if (gc != gcs[gcs.Length - 1]) // 加上 tab符,除了最后一列外
sb.Append(Convert.ToChar(Keys.Tab));
} if (iRow != iSelRowIndexs[iSelRowIndexs.Length - 1]) // 加上换行符。除了最后一行外
sb.Append(Convert.ToChar(Keys.Return));
} Clipboard.SetText(sb.ToString());
} // 这里暂时只有 decimal型数据,并且每次粘贴只有一列的
// 要么是折扣列,要么是评估收视率列
private void PasteToGrid(DevExpress.XtraGrid.Views.BandedGrid.BandedGridView bandedGrid,int iStartRowIndex,int iSelRowCount,string sFieldName)
{
string sClipBoard = Clipboard.GetText().TrimEnd('\n').TrimEnd('\r'); // 去掉最后一个\r\n;
string[] aRow = sClipBoard.Split(Convert.ToChar(Keys.Return)); // 取得行
string[] aCell = new string[1]; if (aRow == null || aRow.Length == 0)
{
Common.DisplayMsg(this.Text,"粘贴板没有数据");
return;
} if (iSelRowCount != aRow.Length)
{
Common.DisplayMsg(this.Text, "选择的数据行数与粘贴板的行数不匹配\r\n\r\n选择行数: " + iSelRowCount + "\r\n粘贴板行数: " + aRow.Length);
return;
} decimal dTemp=0.0M;
bool bResult = false;
for (int i = 0; i < aRow.Length; i++)
{
aCell = aRow[i].Split(Convert.ToChar(Keys.Tab));// 取得列
if (!Common.IsNullOrEmptyObject(aCell[0]))
{
bResult = Decimal.TryParse(aCell[0], out dTemp);
if (dTemp < 0) dTemp = 0;
if (sFieldName == "Discount")
{
if (dTemp == 0) dTemp = 100;
if (dTemp > 100) dTemp = 100;
if (dTemp > 0 && dTemp <= 1) dTemp = dTemp * 100;
}
bandedGrid.SetRowCellValue(iStartRowIndex + i, sFieldName, dTemp);
}
else
{
bandedGrid.SetRowCellValue(iStartRowIndex + i, sFieldName, 0);
}
}
} private void PasteNewRowsToGrid(DevExpress.XtraGrid.Views.BandedGrid.BandedGridView bandedGrid, string[] sFieldNames)
{
string sClipBoard = Clipboard.GetText().TrimEnd('\n').TrimEnd('\r'); // 去掉最后一个\r\n;
string[] aRow = sClipBoard.Split(Convert.ToChar(Keys.Return)); // 取得行
string[] aCell = new string[1]; if (aRow == null || aRow.Length == 0)
{
Common.DisplayMsg(this.Text,"粘贴板没有数据");
return;
} if (sFieldNames.Length != aRow[0].Split(Convert.ToChar(Keys.Tab)).Length)
{
Common.DisplayMsg(this.Text, "需要的列数与粘贴板的列数不匹配\r\n\r\n需要的列数: " + sFieldNames.Length + "\r\n粘贴板行数: " + aRow.Length);
return;
} decimal dTemp=0.0M;
int iTemp = 0;
bool bResult = false;
int iRowIndex = 0; int iMaxDaypartID = Common.GetMaxTableID(sqlHelper.ConnStringCPRP, "DaypartID", "Daypart"); for (int i = 0; i < aRow.Length; i++)
{
bandedGridView1.AddNewRow();
bandedGridView1.UpdateCurrentRow();
iRowIndex = bandedGridView1.RowCount - 1; bandedGridView1.SetRowCellValue(iRowIndex, "DaypartID", ++ iMaxDaypartID); if (! arrAddedDaypartID.Contains(iMaxDaypartID))
{
arrAddedDaypartID.Add(iMaxDaypartID);
} aCell = aRow[i].Split(Convert.ToChar(Keys.Tab));// 取得列
for (int j = 0; j < aCell.Length; j++)
{
bResult = int.TryParse(aCell[0], out iTemp);
if (bResult)
{
bandedGridView1.SetRowCellValue(iRowIndex, bandedGridView1.Columns[sFieldNames[j]], iTemp);
}
else
{
bResult = Decimal.TryParse(aCell[0], out dTemp);
if (bResult)
{
bandedGridView1.SetRowCellValue(iRowIndex, bandedGridView1.Columns[sFieldNames[j]], dTemp);
}
else
{
bandedGridView1.SetRowCellValue(iRowIndex, bandedGridView1.Columns[sFieldNames[j]], aCell[j].Trim('\n'));
}
}
}
}
} //
private void mnuPaste2_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor; string[] sFieldNames = new string[] { "MediaName","StartTime","EndTime","Dayofweek","ProgramName","Position","Cost1","Cost2","Cost3" };
PasteNewRowsToGrid(bandedGridView1,sFieldNames); this.Cursor = Cursors.Default;
}

  

C#、devExpress 的 给bandedGrid加菜单功能 :复制、粘贴的例子(转)的更多相关文章

  1. DevExpress.XtraGrid.Views.BandedGrid.BandedGridView

    使用的是DevExpress.XtraGrid.Views.BandedGrid.BandedGridView 类 没有在工具箱里找到对应控件 ,绕了一下,先创建一个gridcontrol ,然后gr ...

  2. Android中的复制粘贴

    Android中的复制粘贴 The Clipboard Framework 当使用clipboard framework时,把数据放在一个剪切对象(clip object)里,然后这个对象会放在系统的 ...

  3. 远程桌面时plsql的复制粘贴功能失效

    解决办法:重新启动远程桌面上的rdpclip进程就可以复制粘贴了,但是每次重开远程桌面都会出现同样的问题.可以rdpclip这个设置成开机启动.

  4. 不注册COM在Richedit中使OLE支持复制粘贴

    正常情况下在Richedit中使用OLE,如果需要OLE支持复制粘贴,那么这个OLE对象必须是已经注册的COM对象. 注册COM很简单,关键问题在于注册时需要管理员权限,这样一来,如果希望APP做成绿 ...

  5. ios textfield / textview长按复制粘贴中文显示

    当我们在写应用时要复制粘贴文本框内容时,默认显示的文字为英文字体,可按如下步骤设置,显示中文:

  6. 复制粘贴出来的悲剧----spring实现文件下载和HttpStatus.CREATED

    今天真是被自己的懒惰和复制粘贴给坑惨了... 网上有这么一个spring下载文件的最佳实践: @RequestMapping("download") public Response ...

  7. ZeroClipboard跨浏览器复制粘贴

    <!DOCTYPE html> <html> <head> <title>ZeroClipboard跨浏览器复制粘贴</title> < ...

  8. shutil复制粘贴和压缩

    shutil复制粘贴和压缩 shutil 高级的文件.文件夹.压缩包处理模块 @1).将文件内容拷贝到另一个文件中 import shutil shutil.copyfileobj(open(&quo ...

  9. ubuntu快捷复制粘贴

    今天使用putty,纠结复制粘贴的时候,才发现 原来只要选中文本后,就可以中键粘贴 整个桌面环境可用,新技能啊以前居然不知道

随机推荐

  1. 每日英语:When Social Skills Are A Warning

    An uncle starts believing all your sarcastic comments. Or a kindhearted friend never understands any ...

  2. MySQL编码问题集合

    1.以root用户的身份登录,查看编码设置 mysql> SHOW VARIABLES LIKE 'character%'; +--------------------------+------ ...

  3. python操作word之pywin32的安装

    PyCharm 2016.2 官网中文汉化破解版 注册码 http://idea.lanyus.com/ 首先下载安装win32com,下载32位的,不然安装的时候可能检测不到python https ...

  4. redhat6.8服务器版本 yum 源的配置

    阿里云的源地址: http://mirrors.aliyun.com/ 打开后点击帮助: 有如下提示: 不过不能直接使用这个源,因为自己使用的是服务器版本,要修改一个变量,先将源文件下载下来. wge ...

  5. Qt中将QString转换为char *或者相反

    1.将QString转换为std::string,可以通过QString的成员函数toStdString() QString Qstr="123";std::string str= ...

  6. PostgreSQL 配置远程访问

    配置远 程连接PostgreSQL数据库的步骤很简单,只需要修改data目录下的pg_hba.conf和postgresql.conf. pg_hba.conf:配置对数据库的访问权限, postgr ...

  7. 第二百四十六节,Bootstrap弹出框和警告框插件

    Bootstrap弹出框和警告框插件 学习要点: 1.弹出框 2.警告框 本节课我们主要学习一下 Bootstrap 中的弹出框和警告框插件. 一.弹出框 弹出框即点击一个元素弹出一个包含标题和内容的 ...

  8. 在MVC设计模式中,JavaBean的作用是。(选择1项)

    A.Controller B.Model C.业务数据的封装 D.View 解答:B

  9. 股票指数kdj,sar,macd

    http://blog.eastmoney.com/gulingqianketong2011/blog_120832611.html http://blog.sina.com.cn/s/blog_a3 ...

  10. SSH学习三 SESSION

    一.session方法 Session:由同一个IE窗体向同一个WEBAPP发的全部请求的总称,一个会话 同一个会话的多个额请求能够从前到后多个请求.??祖给孙.孙不给祖 浏览器:搜集sessionI ...