Hi,
can you please advise how to adjust CheckBox and DataGridViewCheckBoxColumn to accept Y / N values instead of 0 / 1 ?
Any feedback appreciated,
D
For the DataGridViewCheckBoxColumn use the TrueValue and FalseValue properties.
dataGridView.Columns.Add(new DataGridViewCheckBoxColumn() { TrueValue = "Y", FalseValue = "N", });
For the CheckBox use the Parse and Format events like this:
private void Binding_Format(object sender, ConvertEventArgs e) { e.Value = Object.Equals(e.Value, "Y"); } private void Binding_Parse(object sender, ConvertEventArgs e) { e.Value = (Object.Equals(e.Value, true) ? "Y" : "N"); }
Note: Attach the event handler before adding the binding object.
This works for checkbox:
public class CheckBoxYN : Wisej.Web.CheckBox
{
public string YesNo
{
get
{
if (this.Checked)
return “Y”;
else
return “N”;
}
set
{
if (value == “Y”)
this.Checked = true;
else
this.Checked = false;
}
}
}
and then in page/control/window where you are using this control you need to set databinding to it using:
this.chkExtenede.DataBindings.Add(“YesNo”, <binding source name>, <field to bind to name>);
Please login first to submit.