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
405
ComboBox in Datagrid
posted

Hi,

I have the following situation I got stuck in after reading several posts:

I have a List<CCylinder> this list have Properties like Length, Circumference and StateID.

I managed it to define the fields for the grid like....

<igDP:XamDataGrid Grid.Row="0" HorizontalAlignment="Left" Margin="6,3,0,0" Name="dgCylinder" VerticalAlignment="Top" Height="505" Width="690" AssigningFieldLayoutToItem="dgCylinder_AssigningFieldLayoutToItem" >
                <igDP:XamDataGrid.FieldLayouts >
                    <igDP:FieldLayout Key="Cylinder">
                        <igDP:FieldLayout.Settings>
                            <igDP:FieldLayoutSettings AutoGenerateFields="False" />
                        </igDP:FieldLayout.Settings> 
                        <igDP:FieldLayout.Fields>
                            <igDP:Field Name="Number" Label="Name" />
                            <igDP:Field Name="TotalLength" Label="Total">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings AllowEdit="False" EditAsType="{x:Type sys:Double}"  />
                                </igDP:Field.Settings>
                            </igDP:Field>
                            <igDP:Field Name="Circumference" Label="Circ.">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings AutoSizeOptions="All" AllowEdit="False" EditAsType="{x:Type sys:Double}"  />
                                </igDP:Field.Settings>
                            </igDP:Field>
                            <igDP:Field Name="TypeID" Label="Type">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings AllowEdit="False">
                                </igDP:Field.Settings>
                            </igDP:Field>
                        </igDP:FieldLayout.Fields>
                    </igDP:FieldLayout>
                </igDP:XamDataGrid.FieldLayouts>
            </igDP:XamDataGrid>

 My problem is the following:

The Type ID is defined as List<CStateType> with LocalText and ID as properties.

The grid Itemssource is List<CCylinder>

I want now to display the LOCALTEXT in the grid and not the TypeID.

I read about EditorSTyle and CellPresenterStyle but the maximum I got to work was to display the colum as combobox with the drop down content by the following for field typeID

<igDP:Field Name="TypeID" Label="Type">
  <igDP:Field.Settings>
    <igDP:FieldSettings.CellValuePresenterStyle>
      <Style TargetType="{x:Type igDP:CellValuePresenter}">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
              <ComboBox Name="cmbgridCylinderType" Initialized="cmbgridCylinderType_Initialized">
              </ComboBox>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </igDP:FieldSettings.CellValuePresenterStyle>
  </igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>

I added the list of Items in

private void cmbgridCylinderType_Initialized(object sender, EventArgs e)
{
    ComboBox cb = (ComboBox)sender;
    cb.DisplayMemberPath = "LocalText";
    cb.SelectedValuePath = "ID";
    cb.ItemsSource = CylinderTypes; 
 }
How can I bind the selectedItem of the combobox to the to the typeid of the grid row ?

 

 

  • 138253
    Offline posted

    Hello,

     

    I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter. 

  • 138253
    Offline posted

    Hello,

    Thank you for your post. I have been looking into it and the code you have provided and I suggest you define your Combobox like this:

    <ComboBox ItemsSource="{TemplateBinding Value}" DisplayMemberPath="LocalText" SelectedValuePath="ID"/>  

    This way the displayed text will be LocalText and the Value will be the ID. Please let me know if this helps you or you need further assistance on this matter.

    Looking forward for your reply.