Want to Bind True/Talse data

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

    Want to Bind True/Talse data

    Hi friends,

    I created a dataset in my code and some columns contains True/False
    value. (In SQL Data, the Data Type of these columns are bit)

    I can bind the other data in string format to Text box is ok. Please
    see, like this.

    +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++++++++++
    varDataSetForCu stomerProfile is Dataset

    txtOwnerName.Te xt = varDataSetForCu stomerProfile.T ables[0].Rows[0]
    ["OwnerName"].ToString();

    +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++++++++++
    This is OK.

    But I can't bind the data of "Active" Column (True/False) Value to
    CHEKC BOX control on that FORM. Like this...
    >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>> >>
    this.chkIsActiv e.DataBindings. Add("Checked", this,
    varDataSetForCu stomerProfile.T ables[0].Rows[0]["IsActive"]);

    <<<<<<<<<<<<<<< <<<<<<<<<<<<<<< <<<<<<<<<<<<< <<

    Anyone could please to give me a way to solve this difficulty.

    Thank,
    Victor

  • Marc Gravell

    #2
    Re: Want to Bind True/Talse data

    What is the *exact* error / symptom?
    Well, it should work; at a guess, it could be brecause you are binding
    to the row itself, not the "view" - so no ICustomTypeDesc riptor
    support; this will apply especially if this is an untyped dataset.

    For example, in the following, the "view"-based code has the property,
    the row-based desn't; so try using the view:

    DataTable dt = new DataTable();
    dt.Columns.Add( "IsActive", typeof(bool));
    DataRow row1 = dt.NewRow();
    DataRowView row2 = dt.DefaultView. AddNew();
    var prop1 = TypeDescriptor. GetProperties(r ow1)["IsActive"];
    var prop2 = TypeDescriptor. GetProperties(r ow2)["IsActive"];

    Marc

    Comment

    • Marc Gravell

      #3
      Re: Want to Bind True/Talse data

      I can bind the other data in string format to Text box is ok. Please
      see, like this.
      For the record - that isn't binding; that is assigning; if the
      OwnerName worked via DataBindings, then that would be binding. Does
      this work?

      Comment

      • Hittalar

        #4
        Re: Want to Bind True/Talse data

        On Jun 15, 12:36 pm, Marc Gravell <marc.grav...@g mail.comwrote:
        What is the *exact* error / symptom?
        Well, it should work; at a guess, it could be brecause you are binding
        to the row itself, not the "view" - so no ICustomTypeDesc riptor
        support; this will apply especially if this is an untyped dataset.
        >
        For example, in the following, the "view"-based code has the property,
        the row-based desn't; so try using the view:
        >
                DataTable dt = new DataTable();
                dt.Columns.Add( "IsActive", typeof(bool));
                DataRow row1 = dt.NewRow();
                DataRowView row2 = dt.DefaultView. AddNew();
                var prop1 = TypeDescriptor. GetProperties(r ow1)["IsActive"];
                var prop2 = TypeDescriptor. GetProperties(r ow2)["IsActive"];
        >
        Marc
        Thank for your support.

        My english is poor and so I think you miss my point.

        In my dataset. (Extract data from SQL data)...
        the columns' name and their values are as follow ( for example...)

        CustomerName = "Victor" <varchar(500)/ string>
        Address = "No.(123), V Road" <varchar(500)/ string>
        IsActive = true <int/ bool>



        As you said, I assigned to the text box on the form. and it's ok.

        txtCustomer = CustomerName;
        txtAddress = Address;

        But I can't assign the TRUE value(from the dataset) to the check box
        named "chkIsActiv e" on the form.

        How can I assingn the value (IsActive=true) to this check box?

        Thank.
        Victor


        Comment

        • Marc Gravell

          #5
          Re: Want to Bind True/Talse data

          No; I believe you missed my point - which is that if you are using
          untyped datasets, you need to use the view. The following works fine.

          Marc

          using System.Data;
          using System.Windows. Forms;
          class Program
          {
          static void Main()
          {
          Application.Ena bleVisualStyles ();
          DataTable dt = new DataTable();
          dt.Columns.Add( "IsActive", typeof(bool));
          DataRowView row1 = dt.DefaultView. AddNew();
          DataRowView row2 = dt.DefaultView. AddNew();
          row1["IsActive"] = true;
          row2["IsActive"] = false;
          using (Form form = new Form())
          using (CheckBox cb1 = new CheckBox())
          using (CheckBox cb2 = new CheckBox())
          {
          cb1.Text = "row 1";
          cb2.Text = "row 2";
          cb1.DataBinding s.Add("Checked" , row1, "IsActive") ;
          cb2.DataBinding s.Add("Checked" , row2, "IsActive") ;
          cb2.Dock = cb1.Dock = DockStyle.Top;
          form.Controls.A dd(cb2);
          form.Controls.A dd(cb1);
          Application.Run (form);
          }

          }
          }

          Comment

          • Marc Gravell

            #6
            Re: Want to Bind True/Talse data

            Of course, if you just want to assign, then

            cb.Checked = (bool) row["IsActive"];

            would do (assuming not DBNull)

            Marc

            Comment

            • Hittalar

              #7
              Re: Want to Bind True/Talse data

              On Jun 15, 2:16 pm, Marc Gravell <marc.grav...@g mail.comwrote:
              Of course, if you just want to assign, then
              >
              cb.Checked = (bool) row["IsActive"];
              >
              would do (assuming not DBNull)
              >
              Marc

              You did great man...Thank you so much...
              I want this. Already tested and this is it...

              Thank
              Victor

              Comment

              Working...