#region 粘贴
/// <summary>
/// 粘贴
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPaste_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
string[] data = ClipboardData.Split('\n');
if (data.Length < 1) return;
DataTable datasource =
gridControl1.DataSource as DataTable;
foreach (string row in data)
{
AddRow(row, datasource);
}
gridView1.RefreshData();
}
string ClipboardData
{
get
{
IDataObject iData = Clipboard.GetDataObject();
if (iData == null) return "";
if (iData.GetDataPresent(DataFormats.Text))
return (string)iData.GetData(DataFormats.Text);
return "";
}
set { Clipboard.SetDataObject(value); }
}
void AddRow(string data, DataTable datasource)
{
if (data == string.Empty) return;
string[] rowData = data.Split(new char[] { '\r', '\x09' });
DataRow dr = datasource.NewRow();
for (int i = 0; i < rowData.Length; i++)
{
if (i >= 2) break;
if (i == 0)
dr[0]= Parse(rowData[i]);
else
dr[1]= Parse(rowData[i]);
}
datasource.Rows.Add(dr);
}
double Parse(string value)
{
double result = 0;
double.TryParse(value, out result);
return result;
}
#endregion