Print Page | Close Window

[Resolved]ListConverter Issue

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=487
Printed Date: 11-Jun-2026 at 6:01pm


Topic: [Resolved]ListConverter Issue
Posted By: orcities
Subject: [Resolved]ListConverter Issue
Date Posted: 10-Oct-2007 at 10:01am
I have tried on multiple occassions to use the ListConverter service. I have been successful in getting the items I desire. My problem is that my existing item is never selected.
 
I am not sure if the list is being set after the value is assigned to the combobox.
 
I am setting the list converts in the OnViewContextSet, to verify that my binding manager is not null.



Replies:
Posted By: Linguinut
Date Posted: 10-Oct-2007 at 11:08am
When I bind the list control on the view I use the foreign key field (it will default to textbox, so I change it to combobox).  I place the binding commands (SetBindingListConverter) in the presenter following the base.OnViewSet command.


Posted By: Bill Jensen
Date Posted: 10-Oct-2007 at 1:04pm

Looks like you're calling SetBindingListConverter() in the right place.

Have you tried binding your combo to the relation property rather than the foreign key field?  This retrieves the set of foreign objects, rather than foreign key values.  Then set the DisplayMember to the property (e.g., Name) of the foreign object to appear in the list.
 
Bill J.


Posted By: orcities
Date Posted: 10-Oct-2007 at 1:13pm
I believe that is what I am doing.
 
My example: Address table has foreign key to Types (called AddressType)table
 
I have used hte ControlBindingManager to add AddressType, not the key property. It gives me the combobox.
 
Then in the presenter I use the following to bind the data:
 
EntityPropertyDescriptors.ContactAddressPropertyDescriptor descriptors = EntityPropertyDescriptors.ContactAddress;
SetBindingListConverter(descriptors.AddressType, ListConverterNames.AddressType);
 
It binds the list converter but it doesn't give me my current value. It also has an empty space at the top of the combobox that seems to be a null entity that if selected crashes the application.


Posted By: Linguinut
Date Posted: 10-Oct-2007 at 1:19pm
Read through http://www.ideablade.com/forum/forum_posts.asp?TID=460 - http://www.ideablade.com/forum/forum_posts.asp?TID=460  . . . that may shed a little more light on the subject.  Follow the example in Cabana that has a MakeEntityList and MakeEntityIDList.  Call both from the presenter:
 
SetBindingListConverter(descriptors.AddressType, ListConverterNames.AddressType);
SetBindingListConverter(descriptors.AddressIndex, ListConverterNames.AddressTypeID);
 
Make sure you are binding the combobox to the AddressIndex field, not the related entity list.
 
Also, I added the AutoValidate.EnableAllowFocusChanged (see Cabana) which alleviated some of the navigation issues in the view with empty lists and such.  I may need to adjust that a little later on.


Posted By: orcities
Date Posted: 10-Oct-2007 at 2:01pm
By changing it and binding to the ID and adding that ListConverter it worked. I would of thought that it would work with the entity itself.
 
Tx.
 
One more issue. I am getting and extra blank option in my combobox that is null and if selected causes some issues.


Posted By: Linguinut
Date Posted: 10-Oct-2007 at 2:05pm

the form.autovalidate may be the problem...it was for me.  try adding the following to your view code:

//right after the SetPresenter call
AutoValidate = pPresenter.SetAutoValidation();
 
In the presenter place the following:
 
/// <summary>Set how the View constrains focus change when validation fails.</summary>
/// <remarks>Can also disable auto validation altogether.</remarks>
public AutoValidate SetAutoValidation()
{
    // Play with the choices.
    //return AutoValidate.EnablePreventFocusChange; // Locked in control
    return AutoValidate.EnableAllowFocusChange; // Can move
    //return AutoValidate.Inherit; // Do what the parent container does
    //return AutoValidate.Disable; // Don't autovalidate.
}
 
I tried all of them and this one worked best for me.  For now... I may run into other validation issues later, but I will deal with them as they come up.


Posted By: orcities
Date Posted: 10-Oct-2007 at 3:07pm
That didn't work. If I am adding an new item that first element in the list is blank. And when I try and change it is when it crashes the app due to Object Ref. not set to an instan... you get the point. The first entity in the list is null when it shouldn't even be there.


Posted By: Linguinut
Date Posted: 10-Oct-2007 at 6:18pm

Is it just a straight entity list filling the combobox?

I'll check and see how my lists are getting filled...maybe they have a null entity at the top, too.


Posted By: orcities
Date Posted: 11-Oct-2007 at 7:08am

Yup. It is a straight entity list. If I remember correctly there is a way to make a null entity equal to a base object or base values. But I can't remember how. And I am not sure why it is event putting it there.



Posted By: orcities
Date Posted: 11-Oct-2007 at 9:16am
I ended up overriding the UpdateNullEntity for the Entity and setting the value that was the set as the DisplayMember and it works fine.
 
 



Print Page | Close Window