Solved

binding

Posted on 2011-02-14
3
262 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now