Hi,
I'm having some problems with the RadGridView's DataBindingComplete event handler in a async context and with the Telerik's WinForm RadGridView BestFitColumns method.
I'm developing an winforms with Telerik application that loads data from several db tables and shows them in distinct RadGridViews (one for each table source).
Each of the grids is inside a DocumentWindow. Each DocumentWindow is inside DocumentContainer and all of the DocumentContainers are under a single aggregating Docking.DocumentTabStrip.
The process db table information process is asyncronous so that the UI is free allowing the user to see the information in one table when it becomes available even if one of the other tables are still being loaded.
The first problem is that the DataBindingComplete is only triggered when the user selects the respective tab. Since some of the DataBindingComplete logic can be quite time consuming it leads to a undesired user experience until the data is finally presented.
Is there an alternative event that can be triggered when the data is already available in the RadGridView but without the need of having the user triggering it?
The second is with the way the BestFitColumns method determines the column width. The native DataGridView column's AutoSizeMode contains a option of AllDataCellsExceptHeader that I'm unable to emulate in Telerik.
The documentation for these options is rather scarce and all of the tried options fall short.
Of the available options the closest are the AllCells, DisplayedCells and DisplayedDataCells as the others do not take in account the cell's values.
The AllCells and DisplayedCells use the column headers as input and that makes data spread out too much, which is undesired.
The closest is DisplayedDataCells that sort of works but the logic seems to only use the cells in the rows in the visible range. (I.E.: the rows presented when the grid is presented in the UI). Trying to explain better, if form only displays the first Nth data rows, after the method runs the data will be visible correctly formatted, but if the (N+1) row data has a width larger than any of the first Nth rows the displayed data will be truncated and suffixed with the "..". Is there a way to emulate the AllDataCellsExceptHeader at all?
Thanks for your help.
Regards,
I've implement it using the following logic (snipped code).
(..)
private
async
void
displayButton_Click (
object
sender, EventArgs e) {
(..)
await Task.Run(() => Parallel.ForEach(tablesToRetrieve.Keys, tableID => {
(..)
DocumentWindow docWindow = ((DocumentWindow)returnedDataDocumentTabStrip.Controls[tableName]);
if
(GetDBTableData(tableID, tableArguments,
out
dataTable)) {
docWindow.Invoke((Action)
delegate
{
docWindow.Controls.Add(newRadView(dataTable));
docWindow.Refresh();
});
}
(..)
}));
}
(..)
private
RadGridView newRadView(DataTable dTable) {
RadGridView gridView =
new
RadGridView();
gridView.AutoSizeRows =
false
;
gridView.AllowAutoSizeColumns =
true
;
gridView.ReadOnly =
true
;
gridView.AutoExpandGroups =
true
;
gridView.AllowAddNewRow =
false
;
gridView.AllowDeleteRow =
false
;
gridView.AllowColumnReorder =
true
;
gridView.AllowColumnResize =
true
;
gridView.MultiSelect =
true
;
gridView.SelectionMode= GridViewSelectionMode.CellSelect;
gridView.EnableFiltering =
true
;
gridView.MasterTemplate.EnableFiltering =
true
;
gridView.ShowHeaderCellButtons =
true
;
gridView.EnableAlternatingRowColor =
true
;
gridView.EnableGrouping =
true
;
gridView.MasterTemplate.EnableGrouping =
true
;
gridView.EnableSorting =
true
;
gridView.MasterTemplate.EnableSorting =
true
;
gridView.TableElement.AlternatingRowColor = Color.FromArgb(240, 240, 240);
gridView.TableElement.RowHeight = 18;
gridView.ShowFilteringRow =
true
;
gridView.Dock = DockStyle.Fill;
gridView.AllowSearchRow =
true
;
gridView.SearchRowPosition = SystemRowPosition.Bottom;
gridView.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None;
gridView.Name = dTable.TableName;
/* Arm events handlers
gridView.ViewCellFormatting += gridView_ViewCellFormatting;
gridView.DataBindingComplete += gridView_DataBindingComplete;
gridView.ToolTipTextNeeded += gridView_ToolTipTextNeeded;
/* Load dataTable data */
gridView.BeginUpdate();
gridView.DataSource =
new
BindingSource(dataTable,
null
);
/* Customize table sort assumptions */
gridView.SortDescriptors.Add(
new
SortDescriptor(
"DUMMY_COLUMN"
, System.ComponentModel.ListSortDirection.Descending));
gridView.EndUpdate(
true
);
return
gridView;
}
(..)
private
void
gridView_ViewCellFormatting(
object
sender, CellFormattingEventArgs e) {
if
(e.CellElement.GetType() ==
typeof
(GridHeaderCellElement))
e.CellElement.TextWrap =
true
;
}
(..)
private
void
gridView_DataBindingComplete(
object
sender, GridViewBindingCompleteEventArgs e) {
RadGridView gridView = (RadGridView)sender;
/* Show/Shift/Hide columns to display */
(..)
/* Finally Adjust columns to it's data */
gridView.BestFitColumns(BestFitColumnMode.DisplayedDataCells);
}