Solved

binding

Posted on 2011-02-14
3
263 Views
Last Modified: 2012-05-11
I write the code behind my form in wpf

    Private CustomerData As New CustomerDataSet2
    Private taCust As New CustomerDataSet2TableAdapters.CustomerTableAdapter ' CustomerDataSetTableAdapters.CustomerTableAdapter
    Private taManager As New CustomerDataSet2TableAdapters.TableAdapterManager
    Private View As CollectionView


    Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Me.taCust.Fill(Me.CustomerData.Customer)

        Me.taManager.CustomerTableAdapter = taCust
        MsgBox(Me.taCust.Connection.ConnectionString)

        Me.DataContext = Me.CustomerData.Customer

        Me.View = CollectionViewSource.GetDefaultView(Me.CustomerData.Customer)

    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnFirst.Click
        Me.View.MoveCurrentToFirst()

    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnPrevious.Click
        If Me.View.CurrentPosition > 0 Then
            Me.View.MoveCurrentToPrevious()
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnNext.Click
        If Me.View.CurrentPosition < Me.View.Count - 1 Then
            Me.View.MoveCurrentToNext()
        End If
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLast.Click
        Me.View.MoveCurrentToLast()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnDelete.Click
        If Me.View.CurrentPosition > -1 Then
            Dim row = CType(Me.View.CurrentItem, System.Data.DataRowView).Row
            row.Delete()
        End If
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnAdd.Click
        Dim row = Me.CustomerData.Customer.NewCustomerRow
        row.LastName = "[New]"
        Me.CustomerData.Customer.AddCustomerRow(row)
        Me.View.MoveCurrentToLast()
    End Sub

    Private Sub btnRevert_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnRevert.Click
        If Me.CustomerData.HasChanges Then
            If MessageBox.Show("Are you sure you want to lose all your changes?", Me.Title, MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
                Me.CustomerData.RejectChanges()
            End If
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSave.Click
        Try
            If Me.CustomerData.HasChanges Then
                If Me.taManager.UpdateAll(Me.CustomerData) > 0 Then
                    MsgBox("Saved.")
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Now I need to bind each textbox control with it's field.

It's not success

I am use like this


<TextBox Height="28" Name="txtCustomerID" Width="Auto" IsReadOnly="True" Text="{Binding Path=CustomerID, Mode=OneWay}"/>
            <TextBox Height="28" Name="txtLastName" Width="Auto"  Text="{Binding Path=LastName}"/>
            <TextBox Height="28" Name="txtFirstName" Width="Auto" Text="{Binding Path=FirstName}"/>
            <TextBox Height="28" Name="txtCity" Width="Auto"  Text="{Binding Path=City}"/>
            <TextBox Height="29" Name="Pictrues_locaTextBox" Text="{Binding Path=pictrues_loca, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Width="167" />

How I can do it correctly by programming code ?

0
Comment
Question by:abdallah1973
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 500 total points
ID: 36136968
See my article here on Silverlight to see how Visual Studio helps you in data binding.

http://weblogs.asp.net/nmarun/archive/2009/12/02/using-icommand-silverlight-4.aspx

Arun
0
 

Author Comment

by:abdallah1973
ID: 37365869
No objection
0
 
LVL 27

Expert Comment

by:nmarun
ID: 37365915
'No objection'? care to elaborate?
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question