populate textbox from dataview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Barney

    populate textbox from dataview

    How can I populate a textbox from a dataview? I have a dataset i'm filtering
    on and i want to populate several textboxes based on that filter.

    How can i get that to work?

    I've tried:

    dsDetails = GetCars()
    dvDetails = New DataView
    With dvDetails
    .Table = dsDetails.Table s(0)
    .RowFilter = "CARMAKE=" & "'" & strModel& "'"
    End With
    txtName.DataBin dings("NAME").T oString()

    and i get this error(s)
    Object reference not set to an instance of an object

    or I get:

    This would cause tow bindings in the collection to bind to the same property
    Parameter name: binding

    and i'm using this code
    txtName.DataBin dings.Add(New Binding("Text", dvDetails, "NAME"))

    am I missing something or can this not be done?
  • W.G. Ryan eMVP

    #2
    Re: populate textbox from dataview

    Barney - you need to ensure that you have a DataBinding for the textbox
    before you reference it like that. If the bindings are already set - you
    don't need to reset them each time. If you get rid of this line
    txtName.DataBin dings("NAME").T oString() Do you still get the exception?

    --
    W.G. Ryan, MVP

    www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
    "Barney" <Barney@discuss ions.microsoft. com> wrote in message
    news:49AEB676-57D0-4BE6-8CD7-D95A3E764E40@mi crosoft.com...[color=blue]
    > How can I populate a textbox from a dataview? I have a dataset i'm[/color]
    filtering[color=blue]
    > on and i want to populate several textboxes based on that filter.
    >
    > How can i get that to work?
    >
    > I've tried:
    >
    > dsDetails = GetCars()
    > dvDetails = New DataView
    > With dvDetails
    > .Table = dsDetails.Table s(0)
    > .RowFilter = "CARMAKE=" & "'" & strModel& "'"
    > End With
    > txtName.DataBin dings("NAME").T oString()
    >
    > and i get this error(s)
    > Object reference not set to an instance of an object
    >
    > or I get:
    >
    > This would cause tow bindings in the collection to bind to the same[/color]
    property[color=blue]
    > Parameter name: binding
    >
    > and i'm using this code
    > txtName.DataBin dings.Add(New Binding("Text", dvDetails, "NAME"))
    >
    > am I missing something or can this not be done?[/color]


    Comment

    • Cor Ligthert

      #3
      Re: populate textbox from dataview

      Barney,

      I am curious, why are you using your code like this
      [color=blue]
      > dsDetails = GetCars()
      > dvDetails = New DataView
      > With dvDetails
      > .Table = dsDetails.Table s(0)
      > .RowFilter = "CARMAKE=" & "'" & strModel& "'"
      > End With
      > txtName.DataBin dings("NAME").T oString()
      >[/color]
      You know that with this you type more characters and is used one extra
      instruction (not that the last is in my idea important).

      And while busy your code can be to show the "name" in the txtName confirm
      the currencymanager
      \\\
      dsDetails = GetCars()
      dvDetails as New DataView(dsDeta ils.Tables(0))
      dvDetails.RowFi lter = "CARMAKE=" & "'" & strModel& "'"
      txtName.DataBin dings.Add(New Binding("Text", dvDetails, "NAME"))
      ///
      I hope this helps?

      Cor


      Comment

      • Barney

        #4
        Re: populate textbox from dataview

        yes i still get the error

        "W.G. Ryan eMVP" wrote:
        [color=blue]
        > Barney - you need to ensure that you have a DataBinding for the textbox
        > before you reference it like that. If the bindings are already set - you
        > don't need to reset them each time. If you get rid of this line
        > txtName.DataBin dings("NAME").T oString() Do you still get the exception?
        >
        > --
        > W.G. Ryan, MVP
        >
        > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
        > "Barney" <Barney@discuss ions.microsoft. com> wrote in message
        > news:49AEB676-57D0-4BE6-8CD7-D95A3E764E40@mi crosoft.com...[color=green]
        > > How can I populate a textbox from a dataview? I have a dataset i'm[/color]
        > filtering[color=green]
        > > on and i want to populate several textboxes based on that filter.
        > >
        > > How can i get that to work?
        > >
        > > I've tried:
        > >
        > > dsDetails = GetCars()
        > > dvDetails = New DataView
        > > With dvDetails
        > > .Table = dsDetails.Table s(0)
        > > .RowFilter = "CARMAKE=" & "'" & strModel& "'"
        > > End With
        > > txtName.DataBin dings("NAME").T oString()
        > >
        > > and i get this error(s)
        > > Object reference not set to an instance of an object
        > >
        > > or I get:
        > >
        > > This would cause tow bindings in the collection to bind to the same[/color]
        > property[color=green]
        > > Parameter name: binding
        > >
        > > and i'm using this code
        > > txtName.DataBin dings.Add(New Binding("Text", dvDetails, "NAME"))
        > >
        > > am I missing something or can this not be done?[/color]
        >
        >
        >[/color]

        Comment

        • Barney

          #5
          Re: populate textbox from dataview

          I want to filter out the dataset (dataview) and only show the data in the
          text box were it equals the users selection.

          instead of creating another SQL and another hit to the DB i thought this
          would be easier and a better performance.
          instead of "select * from table where ID = " & selection "


          "Cor Ligthert" wrote:
          [color=blue]
          > Barney,
          >
          > I am curious, why are you using your code like this
          >[color=green]
          > > dsDetails = GetCars()
          > > dvDetails = New DataView
          > > With dvDetails
          > > .Table = dsDetails.Table s(0)
          > > .RowFilter = "CARMAKE=" & "'" & strModel& "'"
          > > End With
          > > txtName.DataBin dings("NAME").T oString()
          > >[/color]
          > You know that with this you type more characters and is used one extra
          > instruction (not that the last is in my idea important).
          >
          > And while busy your code can be to show the "name" in the txtName confirm
          > the currencymanager
          > \\\
          > dsDetails = GetCars()
          > dvDetails as New DataView(dsDeta ils.Tables(0))
          > dvDetails.RowFi lter = "CARMAKE=" & "'" & strModel& "'"
          > txtName.DataBin dings.Add(New Binding("Text", dvDetails, "NAME"))
          > ///
          > I hope this helps?
          >
          > Cor
          >
          >
          >[/color]

          Comment

          • Cor Ligthert

            #6
            Re: populate textbox from dataview

            Barney,

            I did mean why the "with" clause. For the rest I showed how you can do what
            you want, some rows lower in my answer.

            Cor


            Comment

            • Barney

              #7
              Re: populate textbox from dataview

              I follow, just a habit i developed.

              even with the example you provided, i still can't pop a text box.

              "Cor Ligthert" wrote:
              [color=blue]
              > Barney,
              >
              > I did mean why the "with" clause. For the rest I showed how you can do what
              > you want, some rows lower in my answer.
              >
              > Cor
              >
              >
              >[/color]

              Comment

              • Cor Ligthert

                #8
                Re: populate textbox from dataview

                Barney,

                Strange as it looks are this "CARMAKE" and "NAME" you use in a windowform
                case sensitive values (not in a webform). And I use nice spaces between the
                selections however I don't know if that hurts.

                Are you sure the cases are right?

                Cor


                Comment

                • Barney

                  #9
                  Re: populate textbox from dataview

                  I got it working, sort of. when i first load the form and select a cell in my
                  datagrid, the textbox is populate correctly, then when i select another cell
                  i get this error message:

                  This would cause two bindings in the collection to bind to the same
                  property. paramter name binding:

                  how can i get it to work when i select a new selection in my grid?




                  "Cor Ligthert" wrote:
                  [color=blue]
                  > Barney,
                  >
                  > Strange as it looks are this "CARMAKE" and "NAME" you use in a windowform
                  > case sensitive values (not in a webform). And I use nice spaces between the
                  > selections however I don't know if that hurts.
                  >
                  > Are you sure the cases are right?
                  >
                  > Cor
                  >
                  >
                  >[/color]

                  Comment

                  • Cor Ligthert

                    #10
                    Re: populate textbox from dataview

                    Barney,

                    What code are you using now?
                    And how do you set the dataview to the datagrid.

                    Cor


                    Comment

                    • Barney

                      #11
                      Re: populate textbox from dataview

                      here is what i have:

                      dsDetails = GetCars()
                      Dim dvDetails As New DataView(dsDeta ils.Tables(0))
                      dvDetails.RowFi lter = "CARMAKE=" & "'" & strModel & "'"
                      txtName.DataBin dings.Add("Text ", dvDetails, "NAME")
                      Catch ex As Exception
                      MessageBox.Show ("The following error has occurred: " &
                      ex.Message, "Error", MessageBoxButto ns.OK, MessageBoxIcon. Error)
                      End Try

                      "Cor Ligthert" wrote:
                      [color=blue]
                      > Barney,
                      >
                      > What code are you using now?
                      > And how do you set the dataview to the datagrid.
                      >
                      > Cor
                      >
                      >
                      >[/color]

                      Comment

                      • Cor Ligthert

                        #12
                        Re: populate textbox from dataview

                        Barney,

                        You did not show the datagrid as I asked, however when it is like this[color=blue]
                        >
                        > dsDetails = GetCars()
                        > Dim dvDetails As New DataView(dsDeta ils.Tables(0))[/color]
                        datagrid1.datas ource = dvDetails[color=blue]
                        > txtName.DataBin dings.Add("Text ", dvDetails, "NAME")[/color]

                        Than will in the textbox the current selected row be displayed from the
                        datagrid.
                        (What is done by the bindingcontext and the currencymanager )

                        Is that where you are after?

                        Cor


                        Comment

                        • Barney

                          #13
                          Re: populate textbox from dataview

                          what i have is a function that talks to my db and gets me all the data to
                          populate the datagrid. That function returns a dataset, so in my form_Load i
                          have code such as
                          datagrid1.datas ource = GetCars.Table(0 ) which populates the grid just like i
                          want. Then i have code in the datagrid1_selec tionChanged to populate the
                          textboxes based on the users selection (the cell they clicked on). The user
                          can select 1 at a time so when the pick on then them details show up, if they
                          select another one then detais for that selection need to be displayed and so
                          on. I can get the first selection to work correctly, its when I choose
                          another one is when i get the error

                          I'm able to do this on a asp.net web form, so why will this not work on a
                          winForm?



                          "Cor Ligthert" wrote:
                          [color=blue]
                          > Barney,
                          >
                          > You did not show the datagrid as I asked, however when it is like this[color=green]
                          > >
                          > > dsDetails = GetCars()
                          > > Dim dvDetails As New DataView(dsDeta ils.Tables(0))[/color]
                          > datagrid1.datas ource = dvDetails[color=green]
                          > > txtName.DataBin dings.Add("Text ", dvDetails, "NAME")[/color]
                          >
                          > Than will in the textbox the current selected row be displayed from the
                          > datagrid.
                          > (What is done by the bindingcontext and the currencymanager )
                          >
                          > Is that where you are after?
                          >
                          > Cor
                          >
                          >
                          >[/color]

                          Comment

                          • Cor Ligthert

                            #14
                            Re: populate textbox from dataview

                            Why don't you than try to change it as I told.

                            You can do it as well like this.

                            dsDetails = GetCars()
                            txtName.DataBin dings.Add("Text ", dsDetail.Tables (0), "NAME")
                            datagrid1.datas ource = dsDetail.Tables (0)

                            Dont't compare the webform datagrid with the winform datagrid, that is done
                            by a lot of winform programmers for a webform datagrid. It are both grids
                            which has a datasource and with that is in my opinin all said.

                            Cor


                            Comment

                            • Mike

                              #15
                              Re: populate textbox from dataview

                              I'll give this a shot, but the textboxes are only populated based on the
                              selection made by the user in the datagrid. The text box is not in the
                              datagrid, it is on the form below the grid. I'm not sure if your thinking the
                              textbox is in the grid or not. its not in the grid

                              "Cor Ligthert" wrote:
                              [color=blue]
                              > Why don't you than try to change it as I told.
                              >
                              > You can do it as well like this.
                              >
                              > dsDetails = GetCars()
                              > txtName.DataBin dings.Add("Text ", dsDetail.Tables (0), "NAME")
                              > datagrid1.datas ource = dsDetail.Tables (0)
                              >
                              > Dont't compare the webform datagrid with the winform datagrid, that is done
                              > by a lot of winform programmers for a webform datagrid. It are both grids
                              > which has a datasource and with that is in my opinin all said.
                              >
                              > Cor
                              >
                              >
                              >[/color]

                              Comment

                              Working...