Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
615
Use Combox on xamgrid
posted

Hi All,

I want to use a combox on grid with the purpose as below:

combox have value list:

Code        |       Descr

"R"            |       "Report"

"S"            |       "Screen"

......................

this datasource is set at runtime

I want on the xamgrid display the Descr like "Report", "Screen" but when update to datasource it must be the Code like "R", "S".

I have done as following but my code does not run as my expected.

1. Define in XAML

 

<ig:TemplateColumn 

                             Key="ScreenType" 

                             Width="120" 

                             HorizontalContentAlignment="Stretch">

                            <ig:TemplateColumn.ItemTemplate>

                                <DataTemplate>

                                    <TextBlock x:Name="ScreenTypeDisplay" Text="{Binding ScreenType}" />

                                </DataTemplate>

                            </ig:TemplateColumn.ItemTemplate>

                            <ig:TemplateColumn.EditorTemplate>

                                <DataTemplate>

                                    <ig:XamComboEditor  

                                          x:Name="cboScreenTypeList" 

                                          SelectedItem="{Binding ScreenType, Mode=TwoWay}" 

                                          DisplayMemberPath="Value" Loaded="cboScreenTypeList_Loaded" />

                                </DataTemplate>

                            </ig:TemplateColumn.EditorTemplate>

                        </ig:TemplateColumn>

2. Load datasource for combox in cboScreenTypeList_Loaded event:

 

        private void cboScreenTypeList_Loaded(object sender, RoutedEventArgs e)

        {

            SetScreenTypeList(((XamComboEditor)sender));

        }

 

 

private void SetScreenTypeList(XamComboEditor cbo)

        {

            string[] lstLang = new string[] { "Report", "Screen"};

            _eBiz4DSys.Load(_eBiz4DSys.GetSYS_ModuleQuery()).Completed += (sender1, args) =>

            {

                var lang = (from p in _eBiz4DSys.SYS_Languages

                            where lstLang.Contains(p.Code)

                            select new ScreenTypeList

                            {

                                Code = (p.Code == "Report" ? "R" :

                                         p.Code == "Screen" ? "S" :

                                         ""),

                                Value = (hqSys.LangID == 0 ? p.Lang00 :

                                         hqSys.LangID == 1 ? p.Lang01 :

                                         hqSys.LangID == 2 ? p.Lang02 :

                                         hqSys.LangID == 3 ? p.Lang03 :

                                         hqSys.LangID == 4 ? p.Lang04 :

                                         "")

                            });

                cbo.ItemsSource = lang.ToList();                      

                cbo.DisplayMemberPath = "Value";                          

 

            };

        }

When run my code the form show like my attached picture.

Please help me how to use combox in xgrid for my case.

Thanks

Han

 

 

  • 40030
    Offline posted

    Hi Han, 

    I think you should be using an IValueConverter in your TwoWay binding of SelectedItem, to convert to the path that should updated in your ds. 

    Also, for setting the ComboBox's ItemsSource, you probably should try using MVVM. 

    One way to do this, would be to create a custom class: 

    public class ComboDataProvidier
    {
               public IList Data{get;set;}
    }

    Declare an instance of that class in the ResourceDictionary of your UserControl:
    <UserControl.Resources>
         <local:ComboDataProvider x:key="cdp"/>
    </UserControl.Resources>

    Use this to object to bind to your combo:
    ItemsSource="{Binding Data, Source={StaticResource cdp}}" 

    Finally, set the Data  of your cdp from the code behind: 
     ComboDataProvidier cdp = this.Resources["cdp"];
    cdp.Data =  // code to get the data from  _eBiz4DSys

    -SteveZ