Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4108238
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:37:39+00:00 2026-05-20T21:37:39+00:00

Goal: Latest added data should be on the first line in the listview (WPF).

  • 0

Goal:
Latest added data should be on the first line in the listview (WPF). The sorting part is based on column date.

Problem:
Dont’t know how to make a automatical sorting in the listview after adding a data.

Please remember that I don’t use syntax itemsource, List and Binding source.

public partial class FlightForm : Window
{

    public delegate void TakeOffHandler(object source, TakeOffEventArgs e);
    public delegate void ChangeHandler(object source, ChangeRouteEventArgs e);

    public event TakeOffHandler TakeOffEvent;
    public event ChangeHandler ChangeEvent;


    public FlightForm()
    {
        InitializeComponent();

        Title = "Flight ";

        cmbStatus.Visibility = Visibility.Hidden;
        btnLand.Visibility = Visibility.Hidden;
    }



    private void btnStart_Click(object sender, RoutedEventArgs e)
    {

        cmbStatus.Visibility = Visibility.Visible;
        btnLand.Visibility = Visibility.Visible;
        btnStart.Visibility = Visibility.Hidden;

        TakeOffEvent(this, new TakeOffEventArgs("a", "b", DateTime.Now.ToString()));
        ChangeEvent(this, new ChangeRouteEventArgs("aa", "bb", "cc"));


    }




}

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class ControlTower : Window
{
    public ControlTower()
    {
        InitializeComponent();
    }

    private FlightForm myFlightForm;


    private void btnSendNextAirplane_Click(object sender, RoutedEventArgs e)
    {
        myFlightForm = new FlightForm();

        myFlightForm.TakeOffEvent += new FlightForm.TakeOffHandler(PrintOutTakeOff);
        myFlightForm.ChangeEvent += new FlightForm.ChangeHandler(PrintOutChange);
        myFlightForm.Show();

    }




    public void PrintOutTakeOff(object source, TakeOffEventArgs e)
    {

        lstDisplay.Items.Add(new { FlightCode = e.FlightCode, Status = e.Status, Time = e.Time });

    }


    public void PrintOutChange(object source, ChangeRouteEventArgs e)
    {
        string test = e.FlightCode + e.Status + e.Time;

        MessageBox.Show(test);
    }




}

<Window x:Class="Assignment3.ControlTower"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Control Tower" Height="326" Width="420">
    <Grid Height="282">
        <Button Content="Send next Airplane to Runway" Height="23" HorizontalAlignment="Left" Margin="225,250,0,0" Name="btnSendNextAirplane" VerticalAlignment="Top" Width="163" Click="btnSendNextAirplane_Click" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="81,250,0,0" Name="txtFlightCode" VerticalAlignment="Top" Width="120" />
        <Label Content="Next flight:" Height="28" HorizontalAlignment="Left" Margin="6,250,0,0" Name="label1" VerticalAlignment="Top" />
        <ListView Height="244" HorizontalAlignment="Left" Margin="12,0,0,0" Name="lstDisplay" VerticalAlignment="Top" Width="372">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Flight Code" Width="70" DisplayMemberBinding="{Binding FlightCode}" />
                    <GridViewColumn Header="Status" Width="160" DisplayMemberBinding="{Binding Status}" />
                    <GridViewColumn Header="Time" Width="120" DisplayMemberBinding="{Binding Time}" />
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>

<Window x:Class="Assignment3.FlightForm"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="FlightForm" Height="305" Width="352">
    <Grid>
        <Button Content="Start" Height="23" HorizontalAlignment="Left" Margin="0,216,0,0" Name="btnStart" VerticalAlignment="Top" Width="75" Click="btnStart_Click" />
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="81,216,0,0" Name="cmbStatus" VerticalAlignment="Top" Width="120" Visibility="Visible" />
        <Button Content="Land" Height="23" HorizontalAlignment="Left" Margin="217,216,0,0" Name="btnLand" VerticalAlignment="Top" Width="75" />
    </Grid>
</Window>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:37:39+00:00Added an answer on May 20, 2026 at 9:37 pm

    Try to create something like this (slightly modified from MSDN):

    private void Sort(string sortBy, ListSortDirection direction)
    {
        // The MSDN version pass ItemsSource property
        ICollectionView dataView =
          CollectionViewSource.GetDefaultView(lv.Items);
    
        dataView.SortDescriptions.Clear();
        SortDescription sd = new SortDescription(sortBy, direction);
        dataView.SortDescriptions.Add(sd);
        dataView.Refresh();
    }
    

    And use it as follows:

    lstDisplay.Items.Add(new { FlightCode = e.FlightCode, Status = e.Status, Time = e.Time });
    Sort("Time", ListSortDirection.Descending);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can you automatically import the latest build/revision number in subversion? The goal would
My goal is to build an engine that takes the latest HL7 3.0 CDA
Goal Java client for Yahoo's HotJobs Resumé Search REST API . Background I'm used
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
My Goal I would like to have a main processing thread (non GUI), and
My goal is to maintain a web file server separately from my main ASP.NET
My goal here is to create a very simple template language. At the moment,
my goal is to write a stored proc that can collect all field values
The goal: To create a .NET dll i can reference from inside SQL Server
My goal is to recognize simple gestures from accelerometers mounted on a sun spot.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.