I noticed the other day that using the BindingManagerBase's Current property in an expression can spell trouble for your Windows Forms applications. Why? If there are no list items bound to the binding manager, and you try to evaluate whether or not the Current propery is NULL, you'll get an IndexOutOfRangeException exception. That's because the Current property uses the binding manager's index value to retrieve the current list item. Since there are no items in the list, an exception is thrown. Below is an example of what I mean:
The wrong way:// C# Syntax
BindingManagerBase bindingMgrBase = this.BindingContext[dataSet, "TBLMYTABLE"];
if (bindingMgrBase.Current != null) {
// Do something here...
}The right way:// C# Syntax
BindingManagerBase bindingMgrBase = this.BindingContext[dataSet, "TBLMYTABLE"];
if (bindingMgrBase.Position > -1) {
// Do something here...
}Another right way:// C# Syntax
BindingManagerBase bindingMgrBase = this.BindingContext[dataSet, "TBLMYTABLE"];
if (bindingMgrBase.Count > 0) {
// Do something here...
}