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
215
ComboBox for some rows?
posted
Hi, im trying to do something like this... Basically I want to display a ComboBox if the current row meets some condition (Record.DataItem.Inherited), otherwise display a standard textBox.. Is this possible? if so, my current xaml isnt working, any ideas why? Thanks. EDIT: code added to next post.. sorry it looks so nasty..
Parents
  • 6867
    posted

    I suggest you use the FieldSettings property called EditorStyleSelector.  The TargetType of the Style it outputs will be used as the type of editor to display in the cell to which it is applied.  For example, suppose I have these two styles in the XamDataGrid's Resources:

    <igDP:XamDataGrid.Resources>
      <Style x:Key="ComboFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}">
        <Setter Property="ItemsProvider">
          <Setter.Value>
            <igEditors:ComboBoxItemsProvider
              ItemsSource="{Binding Source={StaticResource MyXmlData}, XPath=/items/item}"
              DisplayMemberPath="@text"
              />
          </Setter.Value>
        </Setter>
      </Style>

      <Style x:Key="TextFieldStyle" TargetType="{x:Type igEditors:XamTextEditor}">
        <Setter Property="Margin" Value="2,0" />
      </Style>
    </igDP:XamDataGrid.Resources>

     Then I make a StyleSelector, like so:

     public class MyEditorStyleSelector : StyleSelector
    {
        public static readonly MyEditorStyleSelector Instance = new MyEditorStyleSelector();

        public override Style SelectStyle(object item, DependencyObject container)
        {            
            CellValuePresenter cvp = container as CellValuePresenter;
            if (cvp == null)
                return null;
            
            Foo f = cvp.Record.DataItem as Foo;
            if (f == null)
                return null;

            if(f.Status == MyEnum.Value1)
                return cvp.TryFindResource("ComboFieldStyle") as Style;

            return cvp.TryFindResource("TextFieldStyle") as Style;
        }
    }

    I can use that selector in the XamDataGrid's Field declarations:

    <igDP:FieldLayout>
      <igDP:FieldLayout.Fields>
        <igDP:Field Name="Name" />
        <igDP:Field Name="Status">
          <igDP:Field.Settings>
            <igDP:FieldSettings EditorStyleSelector="{x:Static local:MyEditorStyleSelector.Instance}" />
          </igDP:Field.Settings>
        </igDP:Field>
      </igDP:FieldLayout.Fields>
    </igDP:FieldLayout>

    I hope that helps,

    Josh

Reply Children