Check Box Binding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?=

    Check Box Binding

    I am having trouble with the binding of a check box. I have a form for
    editing and adding reps. I am using a bindingsource and a bindingnavigato r.
    I have on the form an "Active" checkbox, which is bound to the IsActive field
    in the bound data table. It works fine for the reps that are already in the
    table. The problem occurs when I click on the AddNew button on the
    bindingnavigato r. I have the field in the table to default to true, because
    when I add a rep, he will be active. The checkbox is checked when the AddNew
    is clicked, but that data is never written back to my underlying data.
    Everything else is written, but the IsActive field is false, despite what is
    in the check box. How can I get the new rep to have the IsActive field set
    to true?
  • Flomo Togba Kwele

    #2
    Re: Check Box Binding

    Vernon,

    What type of the DataSource? Dataset or customer object: Have you checked the underlying data after
    it is created to make sure Active is set true?

    How do you know it's the binding and not the routine to write it back? Have you checked the
    underlying data just before it is written back to the DB?

    Flomo
    --




    Vernon Peppers wrote:
    I am having trouble with the binding of a check box. I have a form for
    editing and adding reps. I am using a bindingsource and a bindingnavigato r.
    I have on the form an "Active" checkbox, which is bound to the IsActive field
    in the bound data table. It works fine for the reps that are already in the
    table. The problem occurs when I click on the AddNew button on the
    bindingnavigato r. I have the field in the table to default to true, because
    when I add a rep, he will be active. The checkbox is checked when the AddNew
    is clicked, but that data is never written back to my underlying data.
    Everything else is written, but the IsActive field is false, despite what is
    in the check box. How can I get the new rep to have the IsActive field set
    to true?

    Comment

    • =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?=

      #3
      Re: Check Box Binding

      The underlying database is an Access database. I have checked and it is not
      set True.

      The only routine to write the data back is:

      Me.RepsBindingS ource.EndEdit()
      Me.RepsTableAda pter.Update(dt)
      dt.AcceptChange s()

      The rest of the data is written back, so I don't understand why the Active
      field isn't.

      "Flomo Togba Kwele" wrote:
      Vernon,
      >
      What type of the DataSource? Dataset or customer object: Have you checked the underlying data after
      it is created to make sure Active is set true?
      >
      How do you know it's the binding and not the routine to write it back? Have you checked the
      underlying data just before it is written back to the DB?
      >
      Flomo
      --
      >
      >
      >
      >
      Vernon Peppers wrote:
      >
      I am having trouble with the binding of a check box. I have a form for
      editing and adding reps. I am using a bindingsource and a bindingnavigato r.
      I have on the form an "Active" checkbox, which is bound to the IsActive field
      in the bound data table. It works fine for the reps that are already in the
      table. The problem occurs when I click on the AddNew button on the
      bindingnavigato r. I have the field in the table to default to true, because
      when I add a rep, he will be active. The checkbox is checked when the AddNew
      is clicked, but that data is never written back to my underlying data.
      Everything else is written, but the IsActive field is false, despite what is
      in the check box. How can I get the new rep to have the IsActive field set
      to true?
      >

      Comment

      • Flomo Togba Kwele

        #4
        Re: Check Box Binding

        Vernon,

        Place this line between the EndEdit and Update methods:

        Dim row As dsReps.RepsRow = DirectCast(Dire ctCast(RepsBind ingSource.Curre nt, DataRowView).Ro w,
        dsReps.RepsRow)

        The variable row represents a row in the dataset. I'm not sure of the dataset name and table row
        name, but substitute the proper variable names. Then in debug, set a breakpoint and look at the
        value of Active. Is it what you expect?

        You could also use QuickWatch in debug if your familiar with walking the data structure.
        --



        Vernon Peppers wrote:
        The underlying database is an Access database. I have checked and it is not
        set True.
        >
        The only routine to write the data back is:
        >
        Me.RepsBindingS ource.EndEdit()
        Me.RepsTableAda pter.Update(dt)
        dt.AcceptChange s()
        >
        The rest of the data is written back, so I don't understand why the Active
        field isn't.
        >
        "Flomo Togba Kwele" wrote:
        >
        Vernon,

        What type of the DataSource? Dataset or customer object: Have you checked the underlying data
        after it is created to make sure Active is set true?

        How do you know it's the binding and not the routine to write it back? Have you checked the
        underlying data just before it is written back to the DB?

        Flomo
        --




        Vernon Peppers wrote:
        I am having trouble with the binding of a check box. I have a form for
        editing and adding reps. I am using a bindingsource and a bindingnavigato r.
        I have on the form an "Active" checkbox, which is bound to the IsActive field
        in the bound data table. It works fine for the reps that are already in the
        table. The problem occurs when I click on the AddNew button on the
        bindingnavigato r. I have the field in the table to default to true, because
        when I add a rep, he will be active. The checkbox is checked when the AddNew
        is clicked, but that data is never written back to my underlying data.
        Everything else is written, but the IsActive field is false, despite what is
        in the check box. How can I get the new rep to have the IsActive field set
        to true?

        Comment

        • =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?=

          #5
          Re: Check Box Binding

          The only thing that this tells me is that all of the values in the table
          currently are null.

          "Flomo Togba Kwele" wrote:
          Vernon,
          >
          Place this line between the EndEdit and Update methods:
          >
          Dim row As dsReps.RepsRow = DirectCast(Dire ctCast(RepsBind ingSource.Curre nt, DataRowView).Ro w,
          dsReps.RepsRow)
          >
          The variable row represents a row in the dataset. I'm not sure of the dataset name and table row
          name, but substitute the proper variable names. Then in debug, set a breakpoint and look at the
          value of Active. Is it what you expect?
          >
          You could also use QuickWatch in debug if your familiar with walking the data structure.
          --
          >
          >
          >
          Vernon Peppers wrote:
          >
          The underlying database is an Access database. I have checked and it is not
          set True.

          The only routine to write the data back is:

          Me.RepsBindingS ource.EndEdit()
          Me.RepsTableAda pter.Update(dt)
          dt.AcceptChange s()

          The rest of the data is written back, so I don't understand why the Active
          field isn't.

          "Flomo Togba Kwele" wrote:
          Vernon,
          >
          What type of the DataSource? Dataset or customer object: Have you checked the underlying data
          after it is created to make sure Active is set true?
          >
          How do you know it's the binding and not the routine to write it back? Have you checked the
          underlying data just before it is written back to the DB?
          >
          Flomo
          --
          >
          >
          >
          >
          Vernon Peppers wrote:
          >
          I am having trouble with the binding of a check box. I have a form for
          editing and adding reps. I am using a bindingsource and a bindingnavigato r.
          I have on the form an "Active" checkbox, which is bound to the IsActive field
          in the bound data table. It works fine for the reps that are already in the
          table. The problem occurs when I click on the AddNew button on the
          bindingnavigato r. I have the field in the table to default to true, because
          when I add a rep, he will be active. The checkbox is checked when the AddNew
          is clicked, but that data is never written back to my underlying data.
          Everything else is written, but the IsActive field is false, despite what is
          in the check box. How can I get the new rep to have the IsActive field set
          to true?
          >
          >

          Comment

          • Flomo Togba Kwele

            #6
            Re: Check Box Binding

            Vernon,

            Sorry about that. There is probably no current row then. Place that code in the CheckedChanged
            event of the checkbox and look at the Active column, row.Active.


            --



            Comment

            • =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?=

              #7
              Re: Check Box Binding

              row.Active didn't exist, and everything I tried to look at still was null.
              However, I figured out a workaround to take care of my problem. My code is:

              Me.RepsBindingS ource.MoveFirst ()
              For i As Integer = 0 To Me.RepsBindingS ource.Count - 1
              Dim drv As DataRowView = Me.RepsBindingS ource.Current
              Dim row As DataRow = drv.Row
              If row.RowState = DataRowState.Ad ded Then
              row.Item("IsAct ive") = True
              End If
              Me.RepsBindingS ource.MoveNext( )
              Next
              Me.RepsBindingS ource.EndEdit()
              Me.RepsTableAda pter.Update(dt)

              If I step through this code, the value of row.Item("IsAct ive") is DBNull
              before the statement assigning its value. Yet this box is bound to the
              database. I still don't understand why it won't work. I think that we might
              have a bug, but what I have done works.

              "Flomo Togba Kwele" wrote:
              Vernon,
              >
              Sorry about that. There is probably no current row then. Place that code in the CheckedChanged
              event of the checkbox and look at the Active column, row.Active.
              >
              >
              --
              >
              >
              >
              >

              Comment

              Working...