473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++
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

Jun 27 '08 #1
6 1239
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
Jun 27 '08 #2
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?
Jun 27 '08 #3
On Jun 15, 12:36*pm, Marc Gravell <marc.grav...@gmail.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 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
Jun 27 '08 #4
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);
}

}
}
Jun 27 '08 #5
Of course, if you just want to assign, then

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

would do (assuming not DBNull)

Marc
Jun 27 '08 #6
On Jun 15, 2:16*pm, Marc Gravell <marc.grav...@gmail.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
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Karl | last post by:
Hi experts, In my application, I have a employee table containing a gender field which has value "M", "F". I bind gender field to the "checked" property of a group of 2 radio buttons. I hope to...
4
by: Greg Linwood | last post by:
I am wondering what the best approach to binding XML data to an asp:Table from the Page_Load event in a code behind module? I'm using VB.Net and initially approached this by adding a table to the...
3
by: Bob Clegg | last post by:
I am in the same boat as Moondog on the 2nd July. I have a report designed against a dataset. Proved the datasset is OK by dropping a datagrid onto the form and it binds OK to the data. But the...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
0
by: teclioness | last post by:
Hi, I am using gridview for the user to update rows. In a row, there sre two columns, which need to be updated. When the gridview is to be shown, the row should show the values from database....
2
by: sanju | last post by:
Hi, I am struggling to replace a bit value 'True' or 'False' with a image true.gif or false.gif and bind it to a repeater control. I am getting values 'true' or 'false' depending on whether...
1
by: gabe | last post by:
Hi, I have 2 scenarios. (1) works, but (2) doesn't ------------------------------------------------------------ 1) I have sqldatasource control using OracleClient. I'm setting the attributes...
3
by: YMPN | last post by:
Hi Everyone, I'm deen from Riyadh. Please do help me with some problem i have. I have this formview control setup to recieved inputs from user (textbox, dropdownlist, others). After...
7
by: Mike | last post by:
i have a small difficulties with BindingSource and dataGridView bind db has properly opened and bind doesn't works. Unfortunately I didn't find any good example how to connect MS Access with...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.