ListControls icon indicating copy to clipboard operation
ListControls copied to clipboard

DataList

Open holgerschochwitz opened this issue 9 years ago • 7 comments

Hi, how can i use a radiobutton control in the DataList? The binding doesn't work.

Thank you

holgerschochwitz avatar Nov 03 '17 13:11 holgerschochwitz

I use this binding command: Me.AddBinding(ctl, "checked", ctl.Name)

holgerschochwitz avatar Nov 03 '17 14:11 holgerschochwitz

As I recall, property names are case-sensitive. If you specify Checked (with an uppercase C) it should work. Since you're using the ctl.Name property for the field name, you might also check that it is spelled correctly and is using the same case as the underlying field name as well.

EWSoftware avatar Nov 03 '17 14:11 EWSoftware

The names are correct. After the bindings i get a correct value of radiobutton. I can set the radiobutton from false to true but not from true to false. When i use the new row for new datas then i get not a next new row (that works without radiobutton correct) and when i go out the row i get a error from the TemplateControls.cs, Line 681: control.DataBindings.Add(b); {"Ein Objekt kann nicht von DBNull in andere Typen umgewandelt werden."}

I hope you understand me. My englisch is not so good.

Thank you

holgerschochwitz avatar Nov 03 '17 15:11 holgerschochwitz

The same problem have it with the checkboxes.

holgerschochwitz avatar Nov 03 '17 16:11 holgerschochwitz

From the translation of the error message it looks like your field is nullable and the current value when bound is null. Try setting the FormattingEnabled and NullValue properties on the binding which should handle it. FormattingEnabled allows type conversion and formatting to occur when setting the control value and NullValue tells it what to use as a default when the value is null.

Me.AddBinding(ctl, "checked", ctl.Name)
ctl.Bindings(0).FormattingEnabled = True
ctl.Bindings(0).NullValue = False

It's possible you may need to add Binding.Parse and Binding.Format event handlers instead to handle the conversion to/from null when formatting and storing the value.

EWSoftware avatar Nov 03 '17 17:11 EWSoftware

Thank you for your Support My Solution:

Me.AddBinding(ctl, "checked", ctl.Name,, True, AddressOf format_event)

Sub format_event(sender As Object, cevent As ConvertEventArgs) sender.FormattingEnabled = True sender.NullValue = False End Sub

holgerschochwitz avatar Nov 03 '17 21:11 holgerschochwitz

Me.AddBinding(ctl, "checked", ctl.Name, True, AddressOf format_event)

holgerschochwitz avatar Nov 03 '17 21:11 holgerschochwitz