本文介绍了如何逐行向下滚动时如何从DataTable向DataGrid加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private static List< datatable> SplitTable(DataTable originalTable,int batchSize)

{

List< datatable> tables = new List< datatable>();

int i = 0;

int j = 1;

DataTable newDt = originalTable.Clone ();

newDt.TableName =Table_+ j;

newDt.Clear();

foreach(原始表格中的DataRow行。行)

{

DataRow newRow = newDt.NewRow();

newRow.ItemArray = row.ItemArray;

newDt.Rows.Add(newRow);

i ++;

if(i == batchSize)

{

tables.Add(newDt);

j ++;

newDt = originalTable.Clone();

newDt.TableName =Table_ + j;

newDt.Clear();

i = 0;

}

}





 {
// MouseButton mb =(MouseButton)e.OriginalSource;
// ScrollViewer sv =( ScrollViewer)e.OriginalSource;

if ((SampleDatagrid.ScrollInfo.VerticalOffset)> 400 // commencted
// Double d = e。(SampleDatagrid);
if (((SampleDatagrid.Records.Count / 4 )* 3 < SampleDatagrid.ScrollInfo.VerticalOffset) // commenct ed
{
SampleDatagrid.DataSource = SystemDataHelpers.RowList(dt, 0 ,300 + Convert.ToInt32(SampleDatagrid.ScrollInfo。 VerticalOffset));
Scrollcount = Scrollcount + 1 ;
scrollsize = scrollsize + 500 ;
fillDatagrid(ldtdt);
// SampleDatagrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
// SplitTable(dt,size);
}
}









i使用Infragistics控件

 {

if ((SampleDatagrid.ScrollInfo.VerticalOffset) > 400 // commencted
// Double d = e。(SampleDatagrid);
if (((SampleDatagrid.Records.Count / 4 )* 3 < SampleDatagrid.ScrollInfo.VerticalOffset) // commencted
{
SampleDatagrid.DataSource = SystemDataHelpers.RowList(dt, 0 ,300 + Convert.ToInt32(SampleDatagrid.ScrollInfo) .VerticalOffset));
Scrollcount = Scrollcount + 1 ;
scrollsize = scrollsize + 500 ;
fillDatagrid(ldtdt);

}
}



SampleDatagrid.DataSource = dt.DefaultView;



我有解决方案,但是当我加载数据时我的Scroll正在上升



但我想要我的滚动应该只留在那里

解决方案

private static List<datatable> SplitTable(DataTable originalTable, int batchSize)
{
List<datatable> tables = new List<datatable>();
int i = 0;
int j = 1;
DataTable newDt = originalTable.Clone();
newDt.TableName = "Table_" + j;
newDt.Clear();
foreach (DataRow row in originalTable.Rows)
{
DataRow newRow = newDt.NewRow();
newRow.ItemArray = row.ItemArray;
newDt.Rows.Add(newRow);
i++;
if (i == batchSize)
{
tables.Add(newDt);
j++;
newDt = originalTable.Clone();
newDt.TableName = "Table_" + j;
newDt.Clear();
i = 0;
}
}


{
           //MouseButton mb = (MouseButton)e.OriginalSource;
           //ScrollViewer sv = (ScrollViewer)e.OriginalSource;

           if ((SampleDatagrid.ScrollInfo.VerticalOffset) > 400) //commencted
               //Double d=e.(SampleDatagrid);
               if (((SampleDatagrid.Records.Count / 4) * 3) < SampleDatagrid.ScrollInfo.VerticalOffset) //commencted
               {
                   SampleDatagrid.DataSource = SystemDataHelpers.RowList(dt, 0, 300+Convert.ToInt32(SampleDatagrid.ScrollInfo.VerticalOffset));
                   Scrollcount = Scrollcount + 1;
                   scrollsize = scrollsize + 500;
                  fillDatagrid(ldtdt);
                   //SampleDatagrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
                   //SplitTable(dt, size);
               }
       }





i am using Infragistics controls

{
          
           if ((SampleDatagrid.ScrollInfo.VerticalOffset) > 400) //commencted
               //Double d=e.(SampleDatagrid);
               if (((SampleDatagrid.Records.Count / 4) * 3) < SampleDatagrid.ScrollInfo.VerticalOffset) //commencted
               {
                   SampleDatagrid.DataSource = SystemDataHelpers.RowList(dt, 0, 300+Convert.ToInt32(SampleDatagrid.ScrollInfo.VerticalOffset));
                   Scrollcount = Scrollcount + 1;
                   scrollsize = scrollsize + 500;
                  fillDatagrid(ldtdt);
                  
               }
       }


SampleDatagrid.DataSource = dt.DefaultView;

I got Solution but my Scroll is going top when i load data

but i want to My scroll should stay there only

解决方案


这篇关于如何逐行向下滚动时如何从DataTable向DataGrid加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:13