Solved

binding

Posted on 2011-02-14
3
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

729 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