这个目前没有其他的办法,如果只是要粘贴值的话,可以禁用autoclipboard,
通过代码从剪切板获取文本,然后自己循环设置到未隐藏的单元格中,代码如下,在PreviewKeyDown事件中判断ctrl+v
- private void C1FlexGrid3_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
- {
-
- if(e.KeyCode== Keys.V&&e.Modifiers== Keys.Control)
- {
- var pasteStr=Clipboard.GetText();
- var rows= pasteStr.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
- var colscount = rows[0].Split(new string[] { "\t" }, StringSplitOptions.None).Length;
-
- var hitinfo=c1FlexGrid3.HitTest();
- var visiablerows = getVisiableRowList(hitinfo.Row, rows.Length);
- var visiablecols = getVisiableColList(hitinfo.Column, colscount);
- for (int i=0;i< rows.Length; i++)
- {
- var values = rows[i].Split(new string[] { "\t" }, StringSplitOptions.None);
- for (int j = 0; j < values.Length; j++)
- {
- c1FlexGrid3[visiablerows[i], visiablecols[j]] = values[j];
- }
- }
- }
- }
- private int[] getVisiableRowList(int startrow,int rowcount)
- {
- List<int> rowlist = new List<int>();
- while (startrow<c1FlexGrid3.Rows.Count&& rowlist.Count<rowcount)
- {
- if (c1FlexGrid3.Rows[startrow].Visible)
- rowlist.Add(c1FlexGrid3.Rows[startrow].Index);
- startrow++;
- }
- return rowlist.ToArray();
- }
- private int[] getVisiableColList(int startcol, int colcount)
- {
- List<int> collist = new List<int>();
- while (startcol < c1FlexGrid3.Cols.Count && collist.Count < colcount)
- {
- if (c1FlexGrid3.Cols[startcol].Visible)
- collist.Add(c1FlexGrid3.Cols[startcol].Index);
- startcol++;
- }
- return collist.ToArray();
- }
复制代码
|