Set ComboBox to an item when bound to objects

Use Object.Equals.
Then set the combobox selecteditem to a new instance of the object with the required ID or other.
Sample Equals

Public Overrides Function Equals(obj As Object) As Boolean
    If obj Is Nothing Then
        Return False
    End If
    Return CType(obj, Customer).ID = Me.ID
End Function

Deleted row information cannot be accessed through the row. Including with Lambda functions.

Error message
Deleted row information cannot be accessed through the row.
This may occur when using Lambda functions and in other scenarios as well.

Dim dtTotal = dsBusiness1.InvoiceDetail.Where(Function(r1) r1.InvoiceNo = cInvoice.InvoiceNo AndAlso r1.RowState <> DataRowState.Deleted)

Solution 1
Dim dtTotal = dsBusiness1.InvoiceDetail.Where(Function(r1) r1.RowState <> DataRowState.Deleted AndAlso r1.InvoiceNo = cInvoice.InvoiceNo)

Solution 2
Use AcceptChanges on datatable to force deletions to clear



Catch ex As Exception
End Try

Datatable internal index is corrupted ‘5’ – on Dataset save


Issue 5: When a Merge operation occurs, the record manager may become corrupted if the target row is in the edit state

I got this when i was repeatedly updating totals in databound text boxes from Detail rows into the Header table on every move or listchanged. Then bindingsource.addnew, then fill in data, then try and save giving error:- Datatable internal index is corrupted ‘5’

Solutions included:

  1. Remove data binding to text boxes. Write these when updating totals.
  2. Write totals to HeaderRow only if saving
  3. Also found that GetTotals was being called 3 times, on list clear, on parent bindingsource move, on fill detail.
    Controlled this better by putting a SuspendRefreshFlag, before LoadDetail, then after load, GetTotal, Then SuspendRefreshFlag = False again.
  4. Also in ListChanged event use the ByVal e As System.ComponentModel.ListChangedEventArgs

If e.ListChangedType <> System.ComponentModel.ListChangedType.Reset Then
End If


  1. First occurrence at first writing of this post
  2. frmInvoiceDetail – Dec 2012
    • was in ListChanged



Binding a setting to a Property at Design Time. Windows Forms


Window form and control properties may be bound to Application Settings, by expanding the Application Settings at the top of the control properties.
This works fine, for say BackColor. However be warned, there is then a marker by the related bound property. If you then set this manually, this is actually bi-directional and you will change it in the Settings file at the same time, and hence all accross your application, which is probably not your intended action.

See Microsoft Book 70-505 Windows Forms p 587

Gap in market


  • Monitors which work in sunlight. Especially for laptop.

How to use namespaces in XAML WPF including to refer to a converter (maybe other code too)

Place in header part of file. My initial mistake was
Should have been
Need to include the assembly, even if it is the same project.
In this code local gives the namespace a short name.

Next using the namespace in XAML

    <local:ButtonCenterConverter x:Key=”DivideByTwo”></local:ButtonCenterConverter>

How to do Animation in WPF


How to extract an animation to a resource by using style
Also How to perform a scale transform in XAML

<ResourceDictionary xmlns=

<Style TargetType=”Button”>
<EventTrigger RoutedEvent=”Button.MouseEnter”>
Storyboard.TargetProperty=”(RenderTransform).ScaleTransform.ScaleX)” To=”1.1″ Duration=”0:0:0.15″ />
<!–AutoReverse=”True” RepeatBehavior=”2x”–>
<DoubleAnimation Storyboard.TargetProperty=”(RenderTransform).(ScaleTransform.ScaleY)” To=”1.1″ Duration=”0:0:0.15″ />


Storyboard.TargetProperty=”Button.Height” To=”80″ Duration=”0:0:0.2″ />–>

<EventTrigger RoutedEvent=”Button.MouseLeave”>
<DoubleAnimation Storyboard.TargetProperty=”(RenderTransform).(ScaleTransform.ScaleX)” To=”1.0″Duration=”0:0:0.15″ />

<!–AutoReverse=”True” RepeatBehavior=”2x”–></Storyboard></BeginStoryboard>
Storyboard.TargetProperty=”(RenderTransform).(ScaleTransform.ScaleY)” To=”1.0″ Duration=”0:0:0.15″ />
<Setter Property=”RenderTransform”>
ScaleX=”1″ ScaleY=”1″
<!–CenterX=”{Binding Path=ActualWidth, ElementName=Button,Converter=}”–>

How to override a global style

Use Style=”{x:Null}”

How to perform a procedurally animated growing buttons using a scale transform

See Wrox VB2010 p214

How to perform XAML animation: First Success

             <Button Content=”Load” HorizontalAlignment=”Left” Name=”LoadButton” VerticalAlignment=”Top” Width=”75″ >
                    <EventTrigger RoutedEvent=”Button.MouseEnter”>
                                        Storyboard.TargetProperty=”Opacity” From=”1.0″ To=”0.0″ Duration=”0:0:1″ AutoReverse=”True” RepeatBehavior=”Forever” />

         <Button Content=”Growing” HorizontalAlignment=”Left” Margin=”479,4,0,0″ Name=”GrowingButton” VerticalAlignment=”Top” Width=”75″ >
                <EventTrigger RoutedEvent=”Button.MouseEnter”>
                                        Storyboard.TargetProperty=”Width” To=”80″ Duration=”0:0:0.5″ AutoReverse=”True” RepeatBehavior=”2x” />

How to use Application.Resources and also ResourceDictionaries in WPF


The help page in MSDN is at:

I originally got this wrong, by trying to create a new Resource dictionary and placing the XAML <Application.Resources> into this new file.
When you create a new WPF application, an Application.xaml file is created automatically. This already contains an <Application.Resources> section, so just add in your new resources direct into here.

How to use Resource Dictionaries

Create Resource Dictionary, possibly putting it in a different folder, perhaps named Assets.
Then in Application.xaml

<ResourceDictionary Source=”Assets\Dictionary1.xaml” />
<ResourceDictionary Source=”Assets\Dictionary2.xaml” />

<–Seem to be only able use Resoure Dictionary or Application.Resources not a mix of both
So Following line is invalid, because of following ResourceDictionaries
May be possible if a Key is used somewhere>–>
<!–<Brush x:Key=”myColorYellow”>Yellow</Brush>–>

Error 1

If on a window or page and “The designer does not support loading dictionaries that mix “ResourceDictionary” items without a key and other items in the same collection”

Solution 1:

Put the other resources inside the ResourceDictionary even if they are designed there.

With thanks to

How to store Resource Dictionaries in a separate assembly and use them

In the following example of use. RDL01 is an external assembly. The word “component” is there as seen here.

<ResourceDictionary Source=”/RDL01;component/Dictionary1.xaml”></ResourceDictionary>
<Button Content=”Hello” Width=”100″ Height=”50″></Button>

How to use the Property Windows for controls to use and extract Resources

Use extract value to resource

Dataset TableAdapter CommandTimeout

If get error:
“Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding”

Setting the connection string timeout does not work.

Following links led me to my own visual basic translation. I found i had to add the check for the commandCollection Is Nothing

Because the DatasetName.Designer.vb is a partial class, it is possible to create a second partial class which will not be overwritten on changes to the dataset. Remember to use

Namespace xxxTableAdapters

    Partial Public Class xxxTableAdapter

        Public WriteOnly Property SetSelectCommandTimeout() As Integer
            Set(ByVal value As Integer)
                If Me._commandCollection Is Nothing Then
                End If
                Me.CommandCollection(0).CommandTimeout = value
                ‘For Each cmd In Me._commandCollection  ‘To do all
                ‘    cmd.CommandTimeout = value
            End Set
        End Property

    End Class

End Namespace