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);
}
(you will be redirected to DevExpress.com to submit your response)