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. 巧用set比较大小,缩短时间复杂度

    struct Node { long long a; long long b; long long c; long long num; int i; bool operator < (const ...

  2. c#省市联动(sqlHelper的应用)

    sqlHelper: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  3. 知乎日报 API 分析

    声明 下面全部 API 均由 知乎(Zhihu.Inc) 提供,本人採取非正常手段获取. 获取与共享之行为或有侵犯知乎权益的嫌疑.若被告知需停止共享与使用.本人会及时删除此页面与整个项目. 请您暸解相 ...

  4. 修改多渠道打包的App名

    archiveNameFormat = '${flavorName}-${projectName}-${versionName}-${versionCode}'

  5. ci框架简单出现的错误[Undefined property: MContacts::$db]

    出现这样的错误时说明自己忘记加载数据库了, application/config/aotuload.php     $autoload['libraries'] = array('database') ...

  6. 集中精力的重要性(The Importance of Focus)

    集中精力的重要性(The Importance of Focus) 在当今激烈竞争的经济中,你需要集中精力使得你公司的独特方面精益求精.并且你需要每天将精力集中在改进你的公司上.通过终极外包,单干型企 ...

  7. python 人脸识别

    """Performs face alignment and calculates L2 distance between the embeddings of image ...

  8. 在Zookeeper中,znode是一个跟Unix文件系统路径相似的节点,可以往这个节点存储或获取数据

    在Zookeeper中,znode是一个跟Unix文件系统路径相似的节点,可以往这个节点存储或获取数据.如果在创建znode时Flag设置为EPHEMERAL,那么当创建这个znode的节点和Zook ...

  9. MyBatis 本是apache的一个开源项目iBatis

    MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis .20 ...

  10. 【BZOJ】1005: [HNOI2008]明明的烦恼(prufer编码+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1005 这里讲得挺清楚的:http://www.cnblogs.com/zhj5chengfeng/p ...