Question

I have a table with 100,000 records and i have a method (using entity framework) that retrieve 10 records, i give it how many records skip to get the next 10 records.

List<Item> GetRecords(int skip = 0);

I load the first 10 records on a list, and set it as datasource of the UltraGrid, how can i call the method to get the next 10 records and add it to the UltraGrid when the scroll reaches the bottom or is near to reach the bottom?

Was it helpful?

Solution

I have a solution for your requirement. Hope this helps you..

First, create a windows form named "test" (say).. Add a ultraGrid in the form..

enter image description here

check the following code:

   public partial class test : Form
   {
    DataTable dtSource = new DataTable();
    int takecount = 50;
    int skipcount = 0;
    DataTable dtResult;

    // CONSTRUCTOR
    public test()
    {
        InitializeComponent();

        // Fill Dummy data here as datasource...

        dtSource.Columns.Add("SNo", typeof(int));
        dtSource.Columns.Add("Name", typeof(string));
        dtSource.Columns.Add("Address", typeof(string));
        int i = 1;
        while (i <= 500)
        {               
            dtSource.Rows.Add(new object[] { i, "Name: " + i, "Address " + i });
            i++;
        }
        dtResult = dtSource.Copy();
        dtResult.Clear();
    }

    // ON FORM LOAD FUNCTION CALL
    private void test_Load(object sender, EventArgs e)
    {            
        ultraGrid1.DataSource = dt_takeCount();
        ultraGrid1.DataBind();


    }

    private DataTable dt_takeCount()
    {            
        if (dtSource.Rows.Count - skipcount <= takecount)
        {
            takecount = dtSource.Rows.Count - skipcount;
        }
        foreach (var item in dtSource.AsEnumerable().Skip(skipcount).Take(takecount))
        {
            dtResult.Rows.Add(new object[] { item.Field<int>("SNo"), item.Field<string>("Name"), item.Field<string>("Address") });
        }
        if (dtSource.Rows.Count - skipcount >= takecount)
        {
            skipcount += takecount;               
        }            
        return dtResult;
    }

    // EVENT FIRED WHEN ON AFTERROWREGIONSCROLL
    private void ultraGrid1_AfterRowRegionScroll(object sender, Infragistics.Win.UltraWinGrid.RowScrollRegionEventArgs e)
    {
        int _pos = e.RowScrollRegion.ScrollPosition;
        if (ultraGrid1.Rows.Count - _pos < takecount)
        {
            dt_takeCount();
        }           
    }        
}

Above code is all that works.. --> "ultraGrid1_AfterRowRegionScroll" function is "AfterRowRegionScroll" event function

--> But be sure that when you choose "takecount", it generates scrollbar, --> when you run above code... the row will be updated by 50 when you scroll,, till 500th row.. because it is the last row.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top