Want to Bind True/Talse data

H

Hittalar

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.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
varDataSetForCustomerProfile is Dataset

txtOwnerName.Text = varDataSetForCustomerProfile.Tables[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.chkIsActive.DataBindings.Add("Checked", this,
varDataSetForCustomerProfile.Tables[0].Rows[0]["IsActive"]);

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

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

Thank,
Victor
 
M

Marc Gravell

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 ICustomTypeDescriptor
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(row1)["IsActive"];
var prop2 = TypeDescriptor.GetProperties(row2)["IsActive"];

Marc
 
M

Marc Gravell

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?
 
H

Hittalar

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 ICustomTypeDescriptor
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(row1)["IsActive"];
        var prop2 = TypeDescriptor.GetProperties(row2)["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 "chkIsActive" on the form.

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

Thank.
Victor
 
M

Marc Gravell

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.EnableVisualStyles();
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.DataBindings.Add("Checked", row1, "IsActive");
cb2.DataBindings.Add("Checked", row2, "IsActive");
cb2.Dock = cb1.Dock = DockStyle.Top;
form.Controls.Add(cb2);
form.Controls.Add(cb1);
Application.Run(form);
}

}
}
 
M

Marc Gravell

Of course, if you just want to assign, then

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

would do (assuming not DBNull)

Marc
 
H

Hittalar

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top