Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DropDownList Binding
Message
De
23/09/2010 17:47:56
 
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01480952
Message ID:
01482484
Vues:
59
>>>>>>>>>>>>Hi,
>>>>>>>>>>>>
>>>>>>>>>>>>I'm struggling with the simplest thing in a .NET Winforms application. I have a field in a table that can take one of two text strings, say "A" or "B".
>>>>>>>>>>>>
>>>>>>>>>>>>I want to use a combobox/dropdownlist for the user to select which one. My problem is getting the combo to show the correct value when skipping through the records. What I have done so far is set my Items collection for the combo to the values I want. But I am unsure of what I need to set to tell the control to display the value in my Client.ClientType business object. There are various properties:
>>>>>>>>>>>>
>>>>>>>>>>>>BindingSource - which I set to "Client" and am pretty sure that is correct.
>>>>>>>>>>>>BindingSourceDisplayMember
>>>>>>>>>>>>BindingSourceValue
>>>>>>>>>>>>BindingValueSource
>>>>>>>>>>>>
>>>>>>>>>>>>I am not sure if these are properties native to the .NET combo or if they are part of MM .NET.
>>>>>>>>>>>>
>>>>>>>>>>>>I have seen some code for a combo on a web form that manually sets the combo's DisplayValue whenever a new record gets displayed. Is that the way I will need to do this?
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>Frank those properties are mm properties for binding and sychronizing a combo box to the value in your table. In your case it sounds like you do not have a table that holds those two values. I wouldn't either if it were only two choice such as "Female / Male" type question. If the values in the combo box match the values stored in your table then you could just select the record with the selectedValue. What are you using to navigate (skip through) your data? Just create a method to move the SelectedValue to match what is in the current record when the record is navigated.
>>>>>>>>>>>
>>>>>>>>>>>Tim
>>>>>>>>>>
>>>>>>>>>>Ah, so those properties are for the source of the lookup list. I have been told that if I were to use the native .Net stuff I should just need to do this:
>>>>>>>>>>
>>>>>>>>>>
myCombo.DataSource = myDataSet.Tables["Client"];
>>>>>>>>>>myCombo.DisplayMember = "ClientType";
>>>>>>>>>>
>>>>>>>>>>Shouldn't it be as easy as that in MM.NET?
>>>>>>>>>>
>>>>>>>>>>I am just using the default form as described in the jump start for winforms. There is a list page where I let the user specify some search criteria and then display a list of the found items, then they can click on the details page. There is also a default navigation toolbar with the form. I've been looking for an "OnNavigate" method or something similar, but not finding anything that looks like the right place. Where would you suggest?
>>>>>>>>>
>>>>>>>>>Binding Source is the source business object for the combo box, and BindingSourceDisplayMember is the specific field you want to display in the combo from the source. Binding SourceValue Member is typically the PK or value that would match what is stored in your table. So if you have a lookup called PolicyType with a policy Type name and a policyPK the binding source would be PolicyType business object, bindingsourceMember could be PolicyType Name and the bindingsourcevalue member would be the policyPK.
>>>>>>>>>
>>>>>>>>>Then for the table where you need to synchronize this, say ClientPolicy you would put that business object in BindingValueSource and the foreign key field where the policyID is stored into VindingValuesourceMember
>>>>>>>>>
>>>>>>>>>If you are not pulling these values from another source table you could just synch that yourself. Finding where to hook into may be the trick but you could respond to a business object navigation also if need be. If you don't find how to do that let me know and i will find it for you.
>>>>>>>>>Tim
>>>>>>>>
>>>>>>>>Hmm... I guess I expected it to be as easy as in VFP :(
>>>>>>>>
>>>>>>>>I'm still struggling at finding where things are in MM.NET so if you could point out where to look that would be very helpful.
>>>>>>>>
>>>>>>>>Is it that again I am doing something non-standard? I would have thought that things like this would have been mentioned in the jump starts or at least be easily found in the help file.
>>>>>>>
>>>>>>>It is not an MM thing. If you are using a combo to hook up a lookup from a lookup table, MM has done this for you like I explained above. Since you are using a combo for just two choices and not from a table, you have to hook it up yourself. You maybe able (I have not tried) to use some of the mm properties to help with it. I will see if I can try that out in the morning. I will also let you know a good place to hook into the navigation. You said you were just using a navigation arrows on the form?
>>>>>>>Tim
>>>>>>
>>>>>>Yes, I am using the standard MM .NET navigation toolbar that is added to the application desktop (not to the form) by setting DisplayNavigationToolbar to ToolBarOnMainForm. However, one can also use the list page to highlight a record in the grid and then click on the Details page.
>>>>>>
>>>>>>So the code that was suggested elsewhere to set the DataSource and DisplayMember properties would not work, or is not applicable in this case?
>>>>>
>>>>>I just sent you an email with some suggested code for hooking up when the record is navigated. You could just set the SelectedValue based on what the current entity is when this method fires because of navigation.
>>>>>Tim
>>>>
>>>>Thanks, I'm looking at it now. I'm still very surprised that I need to manually update the selected value and that the combo is not smart enough to know which item to display automatically.
>>>
>>>Frank,
>>>You don't need to manually update the value. Put your A, B choices in the Items Collection. Don't put anything in the BindingSource,
>>>BindingSourceDisplayMember or BindingSourceValueMember. In the BindingValueSource, put the name of the table to which the control is bound and in the BindingValueSourceMember, put the column name in which the value will be stored. When you need to reference the value for the combo box, instead of using SelectedValue, you will use Text.
>>
>>Linda,
>>
>>I've tried as you suggested but when I display the client record the Client Type Drop DownList does not reflect the value in the table. Is there something else I am missing?
>
>Frank,
>I think I told you wrong. I was thinking I had done this but I think I only used the Item Collection for report criteria drop downs which are not bound to data. The way I handle these is by having a table of miscellaneous codes (MiscLookup) with the code, description, code type and code length. I have a biz object method that loads the data into a table other than the default biz object table, usually passing the name in as a parameter. You can then use the biz object name as the BindingSource. The BindingSourceDisplayMember and BindingSourceValueMember need to have the TableName.ColumnName. Sorry for misleading you.
>Linda

OK, no probs.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform