Load Different Combobox

Topics: Feature Requests, Framework Services
May 20, 2011 at 7:40 AM
Edited May 20, 2011 at 7:42 AM

Hi Community,

I using some 4 or 5 combobox that gets data from my lookup table and load data accordingly 

example:

i have combobox for SALUTE,GENDER,STATUS, etc., 

1. am getting data for these comboboxes from LOOKUP table and i have to load this Comboboxes with appropriate Datas. Using LINQ

for instance. this is my code to load SALUTE combobox,

 

public EntitySet<Lookup> Editsalute
        {
            get { return Cntx.Lookups; }
        }

public IEnumerator<IResult> GetLookupData()
        {          
            yield return new LoadData<Lookup>(Cntx, Cntx.GetLookupsSALUTEQuery(), LoadBehavior.RefreshCurrent);
        }

 

it works fine. But for other comoboboxes i have to hit the DB many time say three times. To solve this can i have a Generic method that can get data for all the combobox in one shot and can i query it using LINQ and load it to the corresponding comboboxes.

can any one give  solution for this please provide me example code..

 

Thanks,

ksnavinkumar@live.com

May 20, 2011 at 1:23 PM

This discussion http://caliburnmicro.codeplex.com/discussions/256994 is about loading data shared between multiple screens.
The proposed solution seems well suited for you scenario, too; at least you can get some desing ideas to tweak. 

May 24, 2011 at 5:02 AM
Edited May 24, 2011 at 5:15 AM

Hi marcoamendola,

Ii am not getting any thing with that link you gave marcoamendola. sorry i cant follow the thing with that link. And, i hope i have missed some in my previous post. whats is am having a form which consist of some number of TEXTBOXES, COMBOBOXs, DatePickers, what need is i have to bind those controls with DATAGRID selected items. the COMBOBOX's should be filled with data from table called LOOKUP and other controls like TEXTBOXES and DATEPICKERS should be filled by data from Accounts table how can i get this work done...

please help me am totally confused.

Thanks,

ksnavinkumar@live.com

May 24, 2011 at 8:35 AM

OK, I have misunderstood your question; I guessed you were searching for a solution to optimize loading of several combo boxes.

Anyway, I'm still having an hard time to figure out your exact issues.
Please try to describe your scenario in more depth (perhaps with a screenshot) and to explain which parts are causing you problems.

I guess you have a sort of master-detail screen with a datagrid along with a detail form; if so, then you have to address at least three different tasks:
1. move the data from the data source to the client: depending on your architecture, you have either to fetch your data from a DB directly (perhaps with an ORM), or to use a service layer (plain WCF or RIA)
2. load a set of item into the datagrid (this is usually accomplished through binding)
3. synchronize the detail form with the item currently selected in the datagrid (there are many options for this, depending on whether you already have all the details available or you have to fetch them for each item individually)

I'm not sure on which of them you got stuck.

Try to focus on each task individually and make sure to get familiar with the related techniques before intergrating the full scenario.
I also suggest you to have a look to some "real world" sample applications:
http://coproject.codeplex.com/ 
http://caliburnmicro.codeplex.com/wikipage?title=2010%20Caliburn.Micro%20Application%20Contest%20Winners&referringTitle=Documentation

 

 

May 24, 2011 at 9:51 AM
Edited May 24, 2011 at 12:37 PM

hi marcoamendola,

 

 

The above screen is my View and the rounded(in red) comboboxes should be filled by Data from LOOKUP TABLE and the grid that am using is below

 

and the binding method am using to bind this grid is below 

public EntitySet<Account> Accounts
        {
            get { return Cntx.Accounts; }
        }
the above property is which i used to bind the datagrid 

and to bind with the grid.datacontext and using the following code 

<Grid Background="#D5EFFF" x:Name="grdDonor" DataContext="{Binding SelectedItem, ElementName=dgDonor}" HorizontalAlignment="Center" Height="615">
and the code for Datagrid 
 <sdk:DataGrid AutoGenerateColumns="False" ColumnWidth="*" IsReadOnly="True" x:Name="dgDonor" ItemsSource="{Binding Accounts}">
                                        <sdk:DataGrid.Columns>
                                            <sdk:DataGridTextColumn Binding="{Binding No}" Header="No"/>
                                            <sdk:DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName"/>
                                            <sdk:DataGridTextColumn Binding="{Binding LastName}" Header="LastName"/>
                                            <sdk:DataGridTextColumn Binding="{Binding Address}" Header="Address"/>
                                            <sdk:DataGridTextColumn Binding="{Binding City}" Header="City"/>
                                            <sdk:DataGridTextColumn Binding="{Binding State}" Header="State"/>
                                            <sdk:DataGridTextColumn Binding="{Binding Zip}" Header="Zip"/>
                                            <sdk:DataGridTextColumn Binding="{Binding Email}" Header="Email"/>
                                        </sdk:DataGrid.Columns>
                                    </sdk:DataGrid>
so i have provided the code and screen. i ll provide you more informations if needed

Thanks
ksnavinkumar@live.com

May 24, 2011 at 10:15 AM

Hi!

It looks to me from the code above as if you are not actually using Caliburn.Micro and/or the MVVM pattern at all (?).

Does your RIA services code live in a code-behind file, or in a viewmodel?  There is an essential difference between the two.

However, I think something like this is what you need:

        public IEnumerator<IResult> GetLookupData()
        {
            yield return new LoadData<Lookup>(Cntx, CntxLookupsQuery(), LoadBehavior.RefreshCurrent);
        }

        public IEnumerable<Lookup> Editsalute
        {
            get { return Cntx.Lookups.Where(x => x.LookupType == "SALUTE").OrderBy(x => x.LookupName); }
        }

        public IEnumerable<Lookup> Editgender
        {
            get { return Cntx.Lookups.Where(x => x.LookupType == "GENDER").OrderBy(x => x.LookupName); }
        }

        public IEnumerable<Lookup> Editstatus
        {
            get { return Cntx.Lookups.Where(x => x.LookupType == "STATUS").OrderBy(x => x.LookupName); }
        }


You would of course still need some code to bind the selected item property of each of the combo boxes to the selected item on the grid (two-way).
It could be that I have completely misunderstood your scenario.  In that case I would propose you post more of your code. 
May 24, 2011 at 11:40 AM

Hi janoveh,

am not getting any result for the above code in my combobox. i mean the LoadData operation was not invoked in you code.

May 24, 2011 at 12:18 PM

Hi!

As I mentioned, you need a a bit more code than what I presented above to get it running.

I would like to see your viewmodel first, in order to give a qualified suggestion about what you need to do.

Where are you calling the GetLookupData() method from? 

How are you binding the combo boxes?

How are you handling the NotifyOfPropertyChange signalling? ...