Combobox Databinding

Combobox Databinding

Old forum URL: forums.lhotka.net/forums/t/772.aspx


rkelley posted on Monday, July 31, 2006

I have several comboboxes and they are all databound to their appropriate property, and they get their list from a namevaluelist collection.

Is there anyway to update the Business Objects data without tabbing from the control?

I have implemented OnSelectedValueChange for several of them and when you pick a new item in the list I call code like this:

   Object.Propert = cboCombo.Value.ToString();

This works fine except for a few things. It calls the method twice while loading the form, when you change the value, and if you are in the control when you close then it calls it there too. It also sets the property value again when you tab out of the control.

In version 1 of CSLA I was using ActiveControlBinder which handled all of this. I was/still am very excited about the drag and drop databinding which is what I am using but am a little leary of this now, because what if a user opens a form, changes one textbox and then clicks save and it does not update the value. (What I mean by clicking save is that I was hoping to do away with the actual save buttons on forms and integrate a common set of save/cancel buttons in the toolbar)

I hope I have not bored everyone to sleep with this but would really appreciate in input and comments.

Thanks

RockfordLhotka replied on Monday, July 31, 2006

There's a property you can set in the Advanced data binding properties dialog to tell data binding to be more agressive on when it grabs the new value from the control and puts it into the object. I don't recall the name of the property - but it has been discussed on the forum a few times now in regards to keystroke-level binding for textbox controls.

JonM replied on Monday, July 31, 2006

with cboObject
.DataSource = Object.GetNVLlist()
.DisplayMember = "Name"
.ValueMember = "Value"
.DataBindings.Add ("SelectedValue",Object, "myObjectID")
.DataBindings(0).DatasourceUpdateMode=OnPropertyChanged
end with

rkelley replied on Monday, July 31, 2006

Thank you so much, you guys are a godsend!

cmay replied on Tuesday, August 01, 2006

Is there anything simliar to this for databinding with a BindingSource against a GridView?

When I have a datagridview with textboxes, I have to hit "enter" after I change the text before I hit "Save" or my changes to the textbox will not be saved.

RockfordLhotka replied on Tuesday, August 01, 2006

Are you calling EndEdit on the bindingsource control?
 
While there could be other factors involved here, given that you are using embedded controls, normally calling EndEdit on the bindingsource is sufficient to cause data binding to get the value from the last control/cell that was being edited.
 
Rocky


From: cmay [mailto:cslanet@lhotka.net]
Sent: Tuesday, August 01, 2006 9:30 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Combobox Databinding

Is there anything simliar to this for databinding with a BindingSource against a GridView?

When I have a datagridview with textboxes, I have to hit "enter" after I change the text before I hit "Save" or my changes to the textbox will not be saved.




Copyright (c) Marimer LLC