We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Databinding and virtual grid functionality

Is there a way to combine some of the functionality of DataBound grids and virtual grids? My data is dynamically modified by various threads (though rather infrequently), so I''d like to take advantage of databinding to keep the grid in sync automatically. However, at any time, the user''s query might use about 10k rows. Only about a dozen will be visible in the grid. I''d like to be able to query the database for the total number and then only load the rows I need from the database into my DataTable? So, I could do something like: DataView dv = new System.Data.DataView(); dv.Table = mytable; dv.Rows = GetNumRows(); //Does a SELECT COUNT(*) FROM my_Table; myGrid.DataSource = dv; myGrid.ViewRowEvent += new ViewRowEventHandler(myGrid_LoadRowEvent); //Loads row in to mytable [Also, is there a way to do this so it works with Grouping. I suppose it would have to use the database''s GROUP BY function since that data isn''t in RAM. This isn''t essential but it would be nice.] Thanks, dan

3 Replies

AD Administrator Syncfusion Team March 19, 2004 11:25 AM UTC

Looking at it further, is the correct idea to override GridModelDataBinder? If so, are there any example of how to do this?


AD Administrator Syncfusion Team March 19, 2004 12:33 PM UTC

To use a derived GridModelDataBinder requires you to derive the grid and the gridmodel as well. Below are some code snippets. In order for the GridGroupingControl to handle grouping, it must have access to all the data. It can only group what it can access.
public class DerDataBoundGrid : GridDataBoundGrid
{
	DerDataBoundGridModel gridModel;
        public DerDataBoundGrid(): base(new DerDataBoundGridModel())
        {
             gridModel = (DerDataBoundGridModel) Model;
        }
        protected override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e)
        {
             base.OnPrepareViewStyleInfo (e);
        }
        protected override GridModelDataBinder CreateBinder()
        {
             return new DerModelDataBinder(gridModel);
        }
}
public class DerModelDataBinder : GridModelDataBinder
{
       DerDataBoundGridModel gridModel;
       public DerModelDataBinder(DerDataBoundGridModel model) : base(model)
       {
            this.gridModel = model;
       }
       CurrencyManager listManager = null;
       CurrencyManager ListManager
       {
             get
             {
                if (this.listManager == null && this.BindingContext != null && this.DataSource != null)
                        return (CurrencyManager) this.BindingContext[this.DataSource, this.DataMember];
                  return this.listManager;
              }
        }
       protected override void QueryCellInfo(GridQueryCellInfoEventArgs e)
       {
             base.QueryCellInfo (e);
       }
       protected override void SaveCellInfo(GridSaveCellInfoEventArgs e)
       {
             base.SaveCellInfo (e);
       }
}
public class DerDataBoundGridModel : GridDataBoundGridModel
{
     public DerDataBoundGridModel()
     {
     }
      protected override void OnQueryCellInfo(GridQueryCellInfoEventArgs e)
     {
           base.OnQueryCellInfo (e);
     }
      protected override void OnSaveCellInfo(GridSaveCellInfoEventArgs e)
     {
          base.OnSaveCellInfo (e);
     }
}


AD Administrator Syncfusion Team March 19, 2004 09:25 PM UTC

So, ignoring Grouping fucntionality, this is how you''d dynamically load rows while still using databinding to handle updates, etc.? Thanks.

Loader.
Up arrow icon