Giter Site home page Giter Site logo

devexpress-examples / winforms-grid-async-load-data-in-unbound-column Goto Github PK

View Code? Open in Web Editor NEW
1.0 56.0 0.0 400 KB

Asynchronously load data into an unbound grid column.

License: Other

C# 49.98% Visual Basic .NET 50.02%
dotnet xtragrid-suite winforms async-loading data-grid grid-control unbound-column windows-forms

winforms-grid-async-load-data-in-unbound-column's Introduction

WinForms Data Grid - Asynchronously load data into an unbound column

This example handles the CustomUnboundColumnData event to load data in the Quantity unbound column.

private void OnCustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) {
    if (e.Column.FieldName == "Quantity")
        if (e.IsGetData) {
            object val = GetSummaryValue(e);
            e.Value = val;
        }
}
private object GetSummaryValue(DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) {
    if (unboundValues.ContainsKey(e.ListSourceRowIndex)) return unboundValues[e.ListSourceRowIndex];
    unboundValues.Add(e.ListSourceRowIndex, "Not Loaded");
    GetDataAsync(e.ListSourceRowIndex);
    return unboundValues[e.ListSourceRowIndex];
}

GetDataAsync asynchronously loads row data:

private void GetDataAsync(int index) {
    GetDataDelegate d = new GetDataDelegate(GetData);
    d.BeginInvoke(index, new AsyncCallback(DataLoaded), null);
}

KeyValuePair<int, object> GetData(int index) {
    int id = Convert.ToInt32(nwindDataSet.Orders[index]["OrderID"]);
    OleDbConnection connection = new OleDbConnection(connectionSting);
    connection.Open();
    string cmdText = string.Format("SELECT SUM({0}) FROM {1} WHERE {2} = {3}", "Quantity", "OrderDetails", "OrderID", id);
    OleDbCommand command = new OleDbCommand(cmdText, connection);
    object val = command.ExecuteScalar();
    Thread.Sleep(500);
    connection.Close();
    return new KeyValuePair<int, object>(index, val);
}

Files to Review

winforms-grid-async-load-data-in-unbound-column's People

Contributors

albertov05 avatar devexpressexamplebot avatar iam0k avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.