QnA
사용언어
(칠해주세요) => (C#) |
사용툴 (VS) : |
운영체제 (OS) : |
public static void PasteFromClipboard2D(GridView gridMain)
{
IDataObject obj = Clipboard.GetDataObject();
//IDataObject obj = Clipboard.GetDataObject().GetData(DataFormats.Text);
string[,] Ls_2DArray = null;
string[] Ls_ColumnNames = GetColumns(gridMain);
int Li_StartRow = gridMain.FocusedRowHandle;
int Li_StartCol = GetColumnIndex(gridMain.FocusedColumn.FieldName , Ls_ColumnNames);
if(obj.GetDataPresent(DataFormats.Text))
{
string Ls_Clipboard = (string)obj.GetData(DataFormats.Text);
string[] Ls_Line = Ls_Clipboard.Replace(Environment.NewLine, "\n").Split('\n');
string[] Ls_OneLineSample = Ls_Line[0].Split('\t');
Ls_2DArray = new string[Ls_Line.Length, Ls_OneLineSample.Length];
int Li_EndRow = Math.Min(Li_StartRow + Ls_Line.Length - 1, gridMain.RowCount);
int Li_EndCol = Math.Min(Li_StartCol + Ls_OneLineSample.Length, gridMain.Columns.Count);
int Li_CntRow = Li_EndRow - Li_StartRow;
int Li_CntCol = Li_EndCol - Li_StartCol;
for(int Li_Y = 0; Li_Y < Li_CntRow; Li_Y++)
{
string [] Ls_OneLine = Ls_Line[Li_Y].Split('\t');
if(Ls_OneLine.Length < Li_CntCol) break;
for(int Li_X = 0; Li_X < Li_CntCol; Li_X++)
{
try
{
gridMain.SetRowCellValue(Li_Y + Li_StartRow, GetColumnName(Li_X + Li_StartCol, Ls_ColumnNames), Ls_OneLine[Li_X].Trim());
}
catch{}
}
}
}
}
public static string[] GetColumns(GridView gridMain)
{
string[] Ls_ColumnNames = null;
Ls_ColumnNames = new string[gridMain.Columns.Count];
for(int i = 0; i < gridMain.Columns.Count; i++)
{
Ls_ColumnNames[i] = gridMain.Columns[i].FieldName;
}
return Ls_ColumnNames;
}
private static int GetColumnIndex(string Ps_ColumnName, string[] Ps_ColumnsArray)
{
int Li_RET = -1;
for (int i = 0; i < Ps_ColumnsArray.Length; i++)
{
if (Ps_ColumnsArray[i] == Ps_ColumnName)
{
Li_RET = i;
break;
}
}
return Li_RET;
}
public static string GetColumnName(int Pi_ColumnIndex, string[] Ps_ColumnArray)
{
if (Pi_ColumnIndex > Ps_ColumnArray.Length - 1) return null;
return Ps_ColumnArray[Pi_ColumnIndex];
}
void gView_Data_KeyPress(object sender, KeyPressEventArgs e)
{
GridView L_View = sender as GridView;
if(e.KeyChar == (char)22)
{
e.Handled = true;
PasteFromClipboard2D(L_View);
}
}
#endregion
이런형식으로 처리했을때
Excel에서 Ctrl +C 했을때 데이타가 안들어오는데
어찌해야도리까요?
데이타를 Excel에서 Ctrl + V , Ctrl + C를하고싶어요~~~
첫댓글 까악 저랑 같이 DevExpress로 윈도우 폼 개발하시는군요.. 같은걸로 개발하시는 분을 만나니 이렇게 반갑다니 ㅋㅋ
https://www.devexpress.com/Support/Center/Example/Details/E3533
https://www.devexpress.com/Support/Center/Example/Details/E831
https://www.devexpress.com/Support/Center/Example/Details/E863
이 3개의 예제가 도움이 될것 같은데요.. 한번 샘플 보시길 바랍니다^^ 그런대 뭘로 개발하세요? vs2013?? 2012??
프레임웍은요??? 4.0?? 4.5??? 저는 xp를 버리기로 해서 4.5로 하고 있는데^^