Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best Way To Do This?
Message
 
To
08/12/2009 14:07:55
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01437955
Message ID:
01438098
Views:
32
Thanks Bonnie. I understand what you're saying, and I like it. I'll implement it.

Thanks!

>Wow Kevin, I can't believe no one replied to this yet.
>
>I have NOT used classes like this for databinding ... as you know, I use DataSets for everything. But, I know you can make use of bindings, like BindingSource and IBindingList ... I just don't have all the particulars of exactly how to do it.
>
>I'd research that if I were you. There is no way that you should have to be clearing and re-adding DataBindings like you're doing. Once you've bound a TextBox, the binding position should dictate which item you'll display in that TextBox, without you having to fiddle around with it. Again, I'm sorry I don't have concrete examples, but it shouldn't be too hard to do.
>
>~~Bonnie
>
>
>>I have created a user control for an address block. It contains the typcial address info fields on it. It has a List property that can be set to a collection of addresses classes. There is also a combo for selecting the type of address.
>>
>>I the combo's SelectedIndexChange event has:
>>
>>
>>private void cboPickList_SelectedIndexChanged(object sender, EventArgs e)
>>{
>>    _SelectedAddressKey = cboPickList.SelectedKey;
>>    _SelectAddress();
>>}
>>
>>
>>The _SelectAddress() method has:
>>
>>
>>private void _SelectAddress()
>>{
>>    // PK of the Address Type Key record
>>    int AddressTypeKey = cboPickList.SelectedKey;
>>
>>    // Clear out the fields on the control
>>    txtStreet1.Text = "";
>>    txtStreet2.Text = "";
>>    txtCity.Text = "";
>>    txtState.Text = "";
>>    txtZipCode.Text = "";
>>
>>    // Find the Address class in the collection
>>    foreach (Address address in _Addresses)
>>    {
>>        if (address.AddressTypeKey == AddressTypeKey)
>>        {
>>            // Clear and rebind the addresss class to the fields on the control
>>            txtStreet1.DataBindings.Clear();
>>            txtStreet2.DataBindings.Clear();
>>            txtCity.DataBindings.Clear();
>>            txtState.DataBindings.Clear();
>>            txtZipCode.DataBindings.Clear();
>>
>>            txtStreet1.DataBindings.Add("Text", address, "Street1");
>>            txtStreet2.DataBindings.Add("Text", address, "Street2");
>>            txtCity.DataBindings.Add("Text", address, "City");
>>            txtState.DataBindings.Add("Text", address, "State");
>>            txtZipCode.DataBindings.Add("Text", address, "PostalCode");
>>
>>            break;
>>        }
>>    }
>>
>>    txtStreet1.Focus();
>>}
>>
>>
>>
>>This works fine for when the user selects an address type that exists in the collection, but for an address type that does not have an address defined, the fields are blank, but nothing is bound to them, I would now need to write code to create a new address, bind to
>>it, and store it back to the collection.
>>
>>Anyone have a better way to do this?
>>
>>Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform