For Loop Performance Issue while Updating Datatable...

  • Thread starter Thread starter ID GO
  • Start date Start date
I

ID GO

Guest
I am updating Real time data from Datagrid to Datatable..

Everything is Working Fine But performance Issue while Pasting 1 Lakh and above data..

1. Wpf Datagrid

2. DatatableModel.GridDatatable.Dt is Datatable

private static async void CommandBinding_CanExecutePaste(object sender, ExecutedRoutedEventArgs e)
{
var datagrid = (DataGrid) sender;

var s = Clipboard.GetText();
var lines = s.Split('\n');
var row = (DataGridRow)datagrid.ItemContainerGenerator
.ContainerFromItem(datagrid.CurrentCell.Item);
var rowindex = datagrid.ItemContainerGenerator.IndexFromContainer(row);
var col = datagrid.CurrentCell.Column.DisplayIndex;
foreach (var line in lines)
{
if (rowindex < DatatableModel.GridDatatable.Dt.Rows.Count && line.Length > 0)
{
var cells = line.Split('\t');
for (var i = 0; i < cells.GetLength(0); ++i)
{
if (col + i <DatatableModel.GridDatatable.Dt.Columns.Count)
{
DatatableModel.GridDatatable.Dt.Rows[rowindex][col + i] = cells.TrimEnd();
}
else
{
break;
}
}
rowindex++;
}
else
{
break;
}
}


How can i improvise the code to Update Faster.

Continue reading...
 
Back
Top