C# C1FlexGrid Virtualization with DataTable

Posted by: sergio.rodrigues on 6 March 2023, 8:43 pm EST

  • Posted 6 March 2023, 8:43 pm EST - Updated 7 March 2023, 2:19 am EST

    Hi. Is it possible to implement this sample of virtualization:

    public class VirtualModeCollectionView : C1VirtualDataCollection<Customer>
    {
       public int TotalCount { get; set; } = 1_000;
       protected override async Task<Tuple<int, IReadOnlyList<Customer>>> GetPageAsync(int pageIndex, int startingIndex, int count, IReadOnlyList<SortDescription> sortDescriptions = null, FilterExpression filterExpression = null, CancellationToken cancellationToken = default(CancellationToken))
       {
          await Task.Delay(500, cancellationToken);//Simulates network traffic.
          return new Tuple<int, IReadOnlyList<Customer>>(TotalCount, Enumerable.Range(startingIndex, count).Select(i => new Customer(i)).ToList());
       }
    } 

    but instead of a customer class, using a DataTable or DataRow implementation?

    A possible implementation would be:

    public class VirtualModeCollectionView : C1VirtualDataCollection<DataRow>
    {
        private readonly string _connectionString;
        private readonly string _selectStatement;
        private readonly int _totalCount;
    
        public VirtualModeCollectionView(string connectionString, string selectStatement, int totalCount)
        {
            _connectionString = connectionString;
            _selectStatement = selectStatement;
            _totalCount = totalCount;
        }
    
        protected override async Task<Tuple<int, IReadOnlyList<DataRow>>> GetPageAsync(int pageIndex, int startingIndex, int count, IReadOnlyList<SortDescription> sortDescriptions = null, FilterExpression filterExpression = null, CancellationToken cancellationToken = default)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                await connection.OpenAsync(cancellationToken);
    
                var command = new SqlCommand(_selectStatement, connection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@StartingIndex", startingIndex);
                command.Parameters.AddWithValue("@Count", count);
                using (var adapter = new SqlDataAdapter(command))
                {
                    var dataTable = new DataTable();
                    adapter.Fill(startingIndex, count, dataTable);
                    return new Tuple<int, IReadOnlyList<DataRow>>(_totalCount, dataTable.Rows.Cast<DataRow>().ToList());
                }
            }
        }
    }
    

    The problem I’m having is, when the information is being shown on grid it shows this:

    These Coumns are properties related to DataRows, and not DataTable columns.

    How can I change this code to reflect Datatable columns?

  • Posted 9 March 2023, 12:49 am EST

    Hi Sergio,

    Apologies for the delay in response. It seems that you have created a similar case on our support portal as well (Case ID: CAS-38591-K9V8L7). We have replied to your query there, and we request you to please continue the thread there only to avoid confusion.

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels