Welcome to the Xceed Community | Help
Community Search  

WPF Grid Combobox Linq to SQL

Sort Posts: Previous Next
  •  06-24-2008, 7:02 AM Post no. 13178

    WPF Grid Combobox Linq to SQL

    Currently i have a grid with a combobox in.  The combobox works fine.  i can change a record and write it back to the table.

    The 2 problems are the textblock when not editing shows the Value not the Display.  I can't figure out how to change this.

    Also the dropdown records of the combobox show the class MYNAMESPACE.tblEquipmentType rather than the values.

    The text of the combobox displays fine also.  I've spent days going round in circles looking through the examples trying to do this.

     

    Here is selections of my XAML and code behind.

            private IEnumerable<tblEquipmentType> etQuery = null;
            public IEnumerable<tblEquipmentType> qEquipmentType
            {
                get
                {
                    if (etQuery == null)
                    {
                        etQuery = from e in db.tblEquipmentTypes
                                  select e;    
                    }
                    return etQuery.ToList();
                }
            }

     *************************** XAML **************************

            <DataTemplate x:Key="typeCellDataTemplate">
                <TextBlock Text="{Binding}"
                        MinHeight="22"
                        TextTrimming="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}, Path=ParentColumn.TextTrimming}"
                        TextWrapping="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}, Path=ParentColumn.TextWrapping}"/>
            </DataTemplate>
            <xcdg:CellEditor x:Key="typeEditor">
                <xcdg:CellEditor.EditTemplate>
                    <DataTemplate>
                        <ComboBox BorderThickness="0"
                             Background="Transparent"
                             Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(TextElement.Foreground)}"
                             VerticalContentAlignment="Top"
                             ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}},Path=qEquipmentType}"
                             DisplayMemberPath="eqType"
                             SelectedValue="{xcdg:CellEditorBinding}"
                             SelectedValuePath="eqTypeID"
                             >
                            <ComboBox.Resources>
                                <Style TargetType="Popup">
                                    <Setter Property="TextElement.Foreground"
                                    Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
                                </Style>
                            </ComboBox.Resources>

                        </ComboBox>

                    </DataTemplate>
                </xcdg:CellEditor.EditTemplate>
            </xcdg:CellEditor>

     ******************** GRID *******************

        <xcdg:DataGridControl Name="dataGridControl1" ItemsSource="{Binding Source={StaticResource cvsEquipment}}" AutoCreateColumns="True" CellEditorDisplayConditions="MouseOverRow" Margin="0,0,0,41.441">
                    <xcdg:DataGridControl.Resources>
                        <Style x:Key="{x:Type xcdg:ScrollTip}" TargetType="xcdg:ScrollTip">
                            <Setter Property="VerticalAlignment" Value="Center" />
                            <Setter Property="HorizontalAlignment" Value="Center" />
                        </Style>
                    </xcdg:DataGridControl.Resources>
                    <xcdg:DataGridControl.View>
                         ...
                    </xcdg:DataGridControl.View>
                    <xcdg:DataGridControl.Columns>
                        <xcdg:Column FieldName="eqID"
                             Title="eqID"
                             Width="125"
                             Visible="False" IsMainColumn="True" />
                        <xcdg:Column FieldName="eqTypeID"
                             Title="Type"
                             Width="125"
                             CellContentTemplate="{StaticResource typeCellDataTemplate}"
                             CellEditor="{StaticResource typeEditor}"
                             Visible="True" />
                    </xcdg:DataGridControl.Columns>
                </xcdg:DataGridControl>

    Filed under: , ,
  •  06-24-2008, 9:16 AM Post no. 13181 in reply to 13178

    Re: WPF Grid Combobox Linq to SQL

    I've tried using the datatabledictionary and the shipperIDDictionary that have been mentioned in other threads but i can't make it work with linq to sql. 
  •  06-27-2008, 6:50 AM Post no. 13261 in reply to 13181

    Re: WPF Grid Combobox Linq to SQL

    I figured the initial problem out now using a IValueConverter class that i worte and bound the TextBlock to it.  I'm still struggling the the dropdown list for the combobox though.  It still displays the class name not the values.

    Does anybody know a solution to this issue.

     

    Many Thanks.

    Darren

  •  06-29-2008, 10:39 AM Post no. 13290 in reply to 13261

    Re: WPF Grid Combobox Linq to SQL

    Hi,

    Try using:

    <ComboBox ... >
         <ComboBox.ItemTemplate>
              <TextBlock Text="{Binding eqType}" />
         </ComboBox.ItemTemplate>
    </ComboBox>

    Hope it works.


    Abdullah Ansari
    Senior Software Engineer
    Outworks Solutions Private Limited

    Everything is okay in the end. If its not okay, then its not the end.
  •  06-30-2008, 4:34 AM Post no. 13301 in reply to 13290

    Re: WPF Grid Combobox Linq to SQL

    Thanks Abdullah you really helped.

    What you suggested didn't quite work but it pointed me in the direction of the solution.

    You probably know it but it would't allow me to put a textblock directly into an combobox.itemtemplate.  Instead i did this.

                              <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding eqType}" />
                                </DataTemplate>
                            </ComboBox.ItemTemplate>

    Many thanks again.

    Darren

  •  06-30-2008, 5:11 AM Post no. 13302 in reply to 13301

    Re: WPF Grid Combobox Linq to SQL

    Yes, that was stupid part of me... Any template CellContentTemplate, ItemTemplate , or EditTemplate will accept only a DataTemplate as its value.

    But I think you can pardon me as I'd replied from my home and away from my development environment.

    Enjoy...


    Abdullah Ansari
    Senior Software Engineer
    Outworks Solutions Private Limited

    Everything is okay in the end. If its not okay, then its not the end.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.