Home > Back-end >  How to display my List member in Listview WPF
How to display my List member in Listview WPF

Time:03-09

i have working state.

<ListView.View>
  <GridView>
    <GridView.Columns>
      <GridViewColumn
        Width="120"
        DisplayMemberBinding="{Binding Status}"
        Header="Durumu" />
      <GridViewColumn
        Width="180"
        DisplayMemberBinding="{Binding FromWho}"
        Header="Kimden" />
      <GridViewColumn
        Width="200"
        DisplayMemberBinding="{Binding Address}"
        Header="Adres" />
      <GridViewColumn
        Width="50"
        DisplayMemberBinding="{Binding Code}"
        Header="Kodu" />
      <GridViewColumn
        Width="0"
        DisplayMemberBinding="{Binding Order}"
        Header="Sipariş" />
    </GridView.Columns>
  </GridView>
</ListView.View>

but this not enough for me.

This is my Error Display

I have wpf application. and I'm learning Binding i can use with Default listview binding like above code (listview). but i making editing customize listview. and bind data

however, while i try display data just appear myList's System name.

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="3*" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <DockPanel Grid.Row="1" VerticalAlignment="Center">
    <ListView
      x:Name="listVActiveOrder"
      Width="560"
      Height="222"
      Margin="10,10,0,0"
      HorizontalAlignment="Left"
      VerticalAlignment="Top"
      SelectionChanged="ListVActiveOrder_SelectionChanged"
      ItemsSource="{Binding TakingOrderList}">
      <ListView.GroupStyle>
        <GroupStyle>
          <GroupStyle.ContainerStyle>
            <Style TargetType="GroupItem">
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate>
                    <Grid>
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition />
                      </Grid.ColumnDefinitions>
                      <TextBlock Grid.Column="0" Text="{Binding Address}" />
                      <TextBlock Grid.Column="1" Text="{Binding FromWho}" />
                    </Grid>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>
          </GroupStyle.ContainerStyle>
        </GroupStyle>
      </ListView.GroupStyle>
    </ListView>
  </DockPanel>
  <ListBox
    x:Name="listProcessed"
    Grid.Row="2"
    Width="79"
    Height="29"
    Margin="721,16,0,0"
    HorizontalAlignment="Left"
    VerticalAlignment="Top"
    Visibility="Hidden" />
</Grid>
public LoginResponse loginResponse;
public RestClient client;
public listviewDeneme()
{
    client = new RestClient(Constants.APIURL);
    InitializeComponent();

}
  

private void ListVActiveOrder_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    listVActiveOrder.DataContext = new TakingOrderVM();
}

Where is my fault?

CodePudding user response:

You can either set the DisplayMemberPath property of the ListView or ListBox to a name of the property of the TakingOrder class that you want to display:

<ListBox
    x:Name="listProcessed"
    DisplayMemberPath="FromWho"
    ...

Or you could define an ItemTemplate:

<ListView
  x:Name="listVActiveOrder"
  Width="560"
  Height="222"
  Margin="10,10,0,0"
  HorizontalAlignment="Left"
  VerticalAlignment="Top"
  SelectionChanged="ListVActiveOrder_SelectionChanged"
  ItemsSource="{Binding TakingOrderList}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding Address}" />
                <TextBlock Grid.Column="1" Text="{Binding FromWho}" />
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

There is no reason to use a ListView over a ListBox if you don't intend to use a GridView though.

  • Related