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

Advertisements

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.

Problem
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

Try

Me.MyBindingSource.RemoveCurrent()
Me.MyBindingSource.EndEdit()
Me.ds1.MyTable.AcceptChanges()

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

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

See  http://support.microsoft.com/kb/932491

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
   GetSumFromDetail()
End If

Occurrences

  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
    xmlns:local="clr-namespace:MyConverters
Should have been
    xmlns:local="clr-namespace:OneWay.WPF.MyConverters
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

<Style.Resources>
    <local:ButtonCenterConverter x:Key=”DivideByTwo”></local:ButtonCenterConverter>
</Style.Resources>

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=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns
:x=”http://schemas.microsoft.com/winfx/2006/xaml”&gt;

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

<!–<DoubleAnimation

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

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

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

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″ >
                <Button.Triggers>
                    <EventTrigger RoutedEvent=”Button.MouseEnter”>
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetName=”LoadButton”
                                        Storyboard.TargetProperty=”Opacity” From=”1.0″ To=”0.0″ Duration=”0:0:1″ AutoReverse=”True” RepeatBehavior=”Forever” />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
                </Button.Triggers>
            </Button>

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

How to use Application.Resources and also ResourceDictionaries in WPF

Application.Resources

The help page in MSDN is at:

http://msdn.microsoft.com/en-us/library/ms746624.aspx?lc=1033

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

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

<–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 http://stackoverflow.com/questions/3818000/how-to-define-resources-and-a-mergedictionary-with-a-key-in-a-sl4-page

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.

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

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
http://www.velocityreviews.com/forums/t123478-how-to-set-commandtimeout-for-getdata-method-of-tableadapter-asp-net-2-0-a.html
http://www.pcreview.co.uk/forums/tableadapter-and-commandtimeout-t2354775.html

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
                    Me.InitCommandCollection()
                End If
                Me.CommandCollection(0).CommandTimeout = value
                ‘For Each cmd In Me._commandCollection  ‘To do all
                ‘    cmd.CommandTimeout = value
                ‘Next
            End Set
        End Property

    End Class

End Namespace