Solved

binding

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

632 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