7 Haziran 2017 Çarşamba

DevExpress WPF GridControl: Adding a ComboBox to a column, binding it to a collection of the row's data

<dxg:GridColumn Header="bb" FieldName="Seviyesi"  ReadOnly="False"  >
       <dxg:GridColumn.EditTemplate>
              <ControlTemplate>
                     <dxe:ComboBoxEdit Name="PART_Editor"
                              HorizontalContentAlignment="Left"
                              ItemsSource="{Binding SelectedItem,
                             Converter={StaticResource  SeviyeComboConverter},
RelativeSource={RelativeSource Mode=FindAncestor,
      AncestorType={x:Type dxg:GridControl}}}"
                              DisplayMember="Name"
                              ValueMember="Code"
                              EditValue="{Binding EditValue,
                             RelativeSource={RelativeSource TemplatedParent}}"
                              IsTextEditable="True"
                              AllowNullInput="True"
                              AutoComplete="True"                            
                              ImmediatePopup="True"/>
                   </ControlTemplate>
              </dxg:GridColumn.EditTemplate>
       </dxg:GridColumn>


 public class SeviyeComboConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {


                int yetkiseviye = ShareDate.GlobalData.TanimList.First(f => f.Ekran_Id == ((ServisBaglanti.BackOfficeEkranRolServiceBaglanti.RefTRolEkranYetki)value).Ekran_Id).seviye;

                List<CodeName> liste = new List<CodeName>();

                for (int i = 0; yetkiseviye + 1 > i; i++)
                {
                    CodeName item = new CodeName { Code = i, Name =  "Seviye " + i };
                    liste.Add(item);

                }
                return liste;
         
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                return value;
            }
            return null;
        }
    }




          <dxg:GridColumn Header="Company"  FieldName="SelectedCompanyId" Width="50" >
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <dxe:ComboBoxEdit Name="PART_Editor"
                                                     ImmediatePopup="True"                                        
                                    ItemsSource="{Binding RowData.Row.Company}"
                                    IsTextEditable="False"
                                    ApplyItemTemplateToSelectedItem="False"
                                   ValueMember="IdCustomer" 
                                   DisplayMember="Name">
                                    <dxe:ComboBoxEdit.DisplayTemplate>
                                        <ControlTemplate>
                                            <TextBlock   Text="{Binding Path=DisplayText, RelativeSource={RelativeSource TemplatedParent}}"></TextBlock>
                                         </ControlTemplate>
                                    </dxe:ComboBoxEdit.DisplayTemplate>
                                </dxe:ComboBoxEdit>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>



                <dxg:GridColumn FieldName="TypeName">
                    <dxg:GridColumn.EditTemplate>
                        <ControlTemplate>
                            <dxe:ComboBoxEdit x:Name="PART_Editor" EditMode="InplaceActive"
                                              EditValue="{Binding EditValue, RelativeSource={RelativeSource Mode=TemplatedParent}, 
                                                            Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                              ItemsSource="{Binding RowData.Row.Types}"
                                              ValueMember="FullName" DisplayMember="FullName">
                            </dxe:ComboBoxEdit>
                        </ControlTemplate>
                    </dxg:GridColumn.EditTemplate>
                </dxg:GridColumn>

Hiç yorum yok: