Radiobutton databinding:

  • Thread starter Babu Mannaravalappil
  • Start date
B

Babu Mannaravalappil

Hi,

I have a radio button group which I want to bind to a table column whose
value is a string. Based on the string value, I want to checkmark one of
the radio buttons. Here is my code in an attempt to do this. But it fails.
The events don't even fire. I don't know what I am missing. All other
databindings (to text boxes and combo boxes even check boxes) seem to work
fine. But then, those controls don't need datatype conversion either. Can
somebody please help?

CatalogsDV is a Dataview of my datasource. And I have a currencyManager that
positions the data. I have no problems there since other controls seem to
work.

Binding b2b = new Binding("Checked", catalogsDV, Const.CATALOGTYPECOLUMN);
b2b.Format += new ConvertEventHandler(FormatCatalogType);
b2b.Parse += new ConvertEventHandler(ParseCatalogType);
this.rdbtnB2B.DataBindings.Add(b2b);
//
//
//
//
private void FormatCatalogType(object sender, ConvertEventArgs e)
{
if (e.DesiredType != typeof(string)) return;
string ctype = (string)e.Value;
if (ctype == "B2B")
this.rdbtnB2B.Checked = true;
else if (ctype == "B2C")
this.rdbtnB2C.Checked = true;
}

private void ParseCatalogType(object sender, ConvertEventArgs e)
{
if (e.DesiredType != typeof(bool)) return;
bool ctype = (bool)e.Value;
if (ctype == true)
e.Value = "B2B";
else if (ctype == false)
e.Value = "B2C";
}

I am confused with the complexity of Databinding. But trying to learn. I
assume the above event methods are correct, at least logically. I have
placed breakpoints inside both the above events. But they don't seem to
fire at all. Can somebody please help?

Babu.
 
R

Richard T. Edwards

My first thought is: Try converting the string to long.

What's the actual field data type?
 
B

Babu Mannaravalappil

It was very stupid of me. I was attaching the events to wrong radio buttons
with almost identical names. So naturally, the event were not firing on the
buttons I was expecting. Thank you for the input though.

Babu.
 

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