Cheat Sheets, Best Practices and Troubleshooting
DevExpress components use the standard Windows Forms Data Binding mechanism. Thus, data binding issues are not usually related to our components directly. The following steps allow you to troubleshoot the issue you're facing.
Steps
- Check if the issue is described in the Known Issues section below.
- Replace the DevExpress component with its standard .NET counterpart and check whether the issue is reproducible. For instance, if you faced an issue with a data-aware component (Grid Control, Tree List, Data Layout Control, etc.) replace it with a standard counterpart. Most often, you can use the standard DataGridView component for such tests. If the issue is still reproducible, this means that it is not directly related to DevExpress and you can look for a solution on the web or on common programming forums.
- Look for similar issues, errors and solutions on the web, Stack Overflow or in our Search Engine.
- If the above steps didn't help - you could not find any information about the error on the web or in our Support Center and resolve the issue, please post a new ticket in our Support Center and share as much information as possible (call stack, steps to reproduce, a project where the issue is reproducible). This information will help us determine the cause of the issue in the fastest and most straightforward way.
Known Issues
Issue 1: Data Bindings and/or Validation doesn’t work when a control is placed on a non-focused tab page of XtraTabControl, Layout Control’s Tabbed Group or the standard Tab Control.
Solution: This behavior usually takes place since data bindings aren't completely initialized until a control is visible for the first time and its handle is created. To resolve this issue, force the bound control's initialization.
If a data bound control is located on an inactive tab page, iterate through each page in the page collection and sequentially select each of them. For example, you can handle the Form.Load event and use the following code in the event handler:
C#foreach (XtraTabPage page in XtraTabControl.TabPages)
XtraTabControl.SelectedTabPage = page;
XtraTabControl.SelectedTabPage = XtraTabControl.TabPages[0];
foreach (LayoutGroup page in TabbedControlGroup.TabPages)
TabbedControlGroup.SelectedTabPage = page;
TabbedControlGroup.SelectedTabPage = TabbedControlGroup.TabPages[0];
Visual BasicFor Each page As XtraTabPage In XtraTabControl.TabPages
XtraTabControl.SelectedTabPage = page
Next page
XtraTabControl.SelectedTabPage = XtraTabControl.TabPages(0)
For Each page As LayoutGroup In TabbedControlGroup.TabPages
TabbedControlGroup.SelectedTabPage = page
Next page
TabbedControlGroup.SelectedTabPage = TabbedControlGroup.TabPages(0)
We've discussed similar issues in the following threads:
GridControl's data-related methods don't function if it is placed on a non focused Tab page
XtraTabControl - Controls aren't validated when placed on invisible tab pages
Note
If you are using DXValidationProvider to validate controls, you can set the ValidateHiddenControls property to False. In this case, DXValidationProvider will not validate controls located on inactive tabs.
Issue 2: Data is not displayed, is not updated or cannot be edited in a data-aware component (Grid Control, Tree List, Data Layout Control, Pivot Grid, Gantt Control).
Solution 1: Make sure that the collection to which you bind the control contains data, the control supports your collection and the collection allows edit operations.
The collection must be one of supported types (e.g., IList, IBindingList or ITypedList). Please refer to the following articles to learn more about supported data sources:
Data Binding Common Concepts
Traditional Data Binding Methods
DevExpress WinForms Cheat Sheet - Supported Data Access Technologies and Data Sources
Tip: You can try replacing a DevExpress control with a standard .NET counterpart (e.g., use DataGridView instead of DevExpress Data Grid) and check your scenario. If the issue does not persist with the standard control, please look for a solution in our Support Center or create a new ticket.
Solution 2: Make sure that modified data is saved into the database.
Open your database and make sure it contains updated data. You can also replace the DevExpress component with its standard .NET counterpart (e.g. DataGridView) and bind it to the same data to ensure that it displays updated data correctly.
Solution 3: Make sure that the BindingContext property of a data-bound component is not null.
Our components use the standard Data Binding mechanism, and so they rely on the BindingContext object. If data is not displayed in a control once its data source is assigned, it's likely that BindingContext was not applied. Usually, this takes place if our components are used outside the .NET environment (e.g. as an VSTO Add-In). Please refer to the following threads for details:
DevExpress WinForms Troubleshooting - Issues with third party application add-ins
Problem with XtraGrid within a PowerPoint VSTO Add-in
Note: the LayoutControl uses its own BindingContext while controls use the parent Form's binding context. To avoid data-binding issues, you can either enable LayoutControl.UseLocalBindingContext or use the Data Layout Control, which has this property enabled by default.
Issue 3: Records and columns are shown in Grid Control, Tree List, Vertical Grid, Pivot Grid, Gantt Control but cells are empty after you assign/re-assign a data source.
Solution 1: Make sure that you specified correct field names for columns (for example, see GridColumn.FieldName) and they match the data source fields. If you assign a new data source, you may need to clear the existing column collection before you assign a new data source: How to assign a new datasource to a Grid at runtime and populate Grid columns
Solution 2: If you handle CustomDraw~ events for custom painting and use DirectX rendering, comment out code of the CustomDraw~ event handlers or disable DirectX mode and check if the issue still occurs. If cell text is now visible, make sure that you are using the e.Cache parameter to paint text. Methods of the e.Graphics object are not in effect in DirectX mode. Please refer to the following help topic for details: DirectX Hardware Acceleration API Limitations.
If this doesn't help, perform the basic steps described in the beginning of this article.
Issue 4: Appointments or tasks are not displayed in the Scheduler or Gantt Control.
Solution: Make sure that mappings are correct. See Scheduler Control Mappings and Gantt Control Data Source.
Issue 5: The following exception occurs when you edit DataTable rows:
- System.Data.RowNotInTableException: 'This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.'
Call-stack:
CodeSystem.Data.dll!System.Data.DataRow.GetDefaultRecord()
System.Data.dll!System.Data.DataRow.this[int].get(int columnIndex)
Solution: This exception is not related to our components directly. Please refer to the following Microsoft documentation for more details about this exception: RowNotInTableException. To resolve the issue, follow the Steps described in the beginning of this article.
Known scenarios that lead to the error:
- Binding a data aware component or BindingSource to the collection returned by the DataTable.ToList method; Solution: bind it directly to DataTable instead.
Issue 6: Focused row is reset when a tabbed document is floated
When you make a tabbed form floating, the form handle is recreated. This results in the following actions:
- The default data binding mechanism recreates the data-aware control's BindingContext.
- The control resets its focused row.
Solution: You can save the focused row index and then restore it. For this, you can handle ~BindingContextChanged and ~.FocusedRowChanged:
C#private void GridControl_BindingContextChanged(object sender, EventArgs e) {
bindingContextChanged = true;
}
bool bindingContextChanged = false;
int focusedRowHandle;
private void GridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {
if (bindingContextChanged) {
bindingContextChanged = false;
GridView view = sender as GridView;
view.FocusedRowHandle = focusedRowHandle;
return;
}
focusedRowHandle = e.FocusedRowHandle;
}
Visual BasicPrivate Sub GridControl_BindingContextChanged(ByVal sender As Object, ByVal e As EventArgs)
bindingContextChanged = True
End Sub
Private bindingContextChanged As Boolean = False
Private focusedRowHandle As Integer
Private Sub GridView_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs)
If bindingContextChanged Then
bindingContextChanged = False
Dim view As GridView = TryCast(sender, GridView)
view.FocusedRowHandle = focusedRowHandle
Return
End If
focusedRowHandle = e.FocusedRowHandle
End Sub
See also:
How to investigate an issue and determine why it occurs in your project
Search keywords: troubleshooting, data binding, tab, tab control