1

i Have xaml code

<ListView Name="List1" Margin="0,33,0,0"

                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollBarVisibility="Visible"
    ItemsSource="{Binding Path=Table}" MouseDoubleClick="List1_MouseDoubleClick">

        <ListView.View>

        <GridView x:Name="_gridView" ColumnHeaderTemplate="{StaticResource BlueHeader}">
            <GridViewColumn x:Name="LoyaltyCode"  Header="Code" DisplayMemberBinding="{Binding Path=LoyaltyCode}"/>
            <GridViewColumn x:Name="LoyaltyName" Header="Name" Width="130" DisplayMemberBinding="{Binding Path=LoyaltyName}" HeaderTemplate="{StaticResource BlueHeaderName}"/>
            <GridViewColumn Header="PurProductPonits" DisplayMemberBinding="{Binding Path=PurProductPonits}"/>
            <GridViewColumn Header="PurProductAmount" DisplayMemberBinding="{Binding Path=PurProductAmount}"/>
            <GridViewColumn x:Name="PurServicePonits" Header="PurServicePonits" DisplayMemberBinding="{Binding Path=PurServicePonits}"/>
            <GridViewColumn Header="PurServiceAmount" DisplayMemberBinding="{Binding Path=PurServiceAmount}"/>
            <GridViewColumn Header="RedeemPoints" DisplayMemberBinding="{Binding Path=RedeemPoints}"/>
            <GridViewColumn Header="RedeemAmount  " DisplayMemberBinding="{Binding Path=RedeemAmount}" />

            <GridViewColumn Header="LoyaltyID" DisplayMemberBinding="{Binding Path=LoyaltyID}" Width="0"/>

            <GridView.ColumnHeaderContainerStyle>
                <Style TargetType="{x:Type GridViewColumnHeader}">
                    <Setter Property="IsEnabled" Value="False"/>
                    <Style.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="TextElement.Foreground" Value="Black"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </GridView.ColumnHeaderContainerStyle>
        </GridView>
    </ListView.View>

</ListView>

And the code behind is

foreach (GridViewColumn column in _gridView.Columns)
{
    if (column.Width == 0)
        continue;

    //ComboBoxItem item = new ComboBoxItem();
    // item.Content=column.Header;
    // item.Tag=column.???;
    // cmbSearch.Items.Add(item);

    cmbSearch.Items.Add(column.Header);
}

I need to fill combo box's display item with column.Header and value item with the "DisplayMemberBinding Path name" For example.. item.Content=Code , item.Tag=LoyaltyCode

daniele3004
  • 13,072
  • 12
  • 67
  • 75
SUHAIL AG
  • 195
  • 1
  • 8
  • not sure what you want. the display item here is column header (which is the same for all the cells in the same column), but what exactly the value item you want here? you mean all the value ***items*** in the same column should be added as Items of the combobox? – King King Oct 13 '14 at 12:50
  • thnks for the response..exact db field name in the each column should be added as value-Items of the combobox. Display Code in Heading, bt the dbField name is LoyaltyCode, I need LoyaltyCode to be added as value field...or simply how can i get the dbField name binded with the colomn?? – SUHAIL AG Oct 13 '14 at 13:13

1 Answers1

2

This answer is a year late, but what you can do is cast the DisplayMemberBinding property of each column as a Binding object, and that way you can access the Path property and get the property name from there. So something like this:

    foreach (GridViewColumnHeader column in _gridView.Columns)
    {
        if (column.Width == 0)
            continue;
        ComboBoxItem item = new ComboBoxItem();
        item.Content=column.Header;
        string property = ((System.Windows.Data.Binding)column.DisplayMemberBinding).Path.Path;
        item.Tag= property;
        cmbSearch.Items.Add(item);

        cmbSearch.Items.Add(column.Header);
    }
reservoirman
  • 119
  • 1
  • 11
  • thanks for answering a year later. helped me. you might want to check for null if the displaymemberbinding is null or any of the paths. – juFo Nov 14 '16 at 15:46