Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Read csv file into wpf C#

public IEnumerable<Person> ReadCSV(string fileName)
{
    // We change file extension here to make sure it's a .csv file.
    // TODO: Error checking.
    string[] lines = File.ReadAllLines(System.IO.Path.ChangeExtension(fileName, ".csv"));

    // lines.Select allows me to project each line as a Person. 
    // This will give me an IEnumerable<Person> back.
    return lines.Select(line =>
    {
        string[] data = line.Split(';');
        // We return a person with the data in order.
        return new Person(data[0], data[1], Convert.ToInt32(data[2]), data[3]);
    });
}
Comment

Read csv file into wpf C#

<ListView x:Name="ListViewPeople">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="First name" Width="100" DisplayMemberBinding="{Binding Path=FirstName}"/>
            <GridViewColumn Header="Last name" Width="150" DisplayMemberBinding="{Binding Path=LastName}"/>
            <GridViewColumn Header="ID" Width="40" DisplayMemberBinding="{Binding Path=ID}"/>
            <GridViewColumn Header="Email" Width="200" DisplayMemberBinding="{Binding Path=Email}"/>
        </GridView>
    </ListView.View>
</ListView>
Comment

Read csv file into wpf C#

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int ID { get; set; }
    public string Email { get; set; }

    public Person(string firstName, string lastName, int id, string email)
    {
        FirstName = firstName;
        LastName = lastName;
        ID = id;
        Email = email;
    }
}
Comment

Read csv file into wpf C#

public MainWindow()
{
    InitializeComponent();

    // We can access ListViewPeople here because that's the Name of our list
    // using the x:Name property in the designer.
    ListViewPeople.ItemsSource = ReadCSV("example");
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# create default instance of type 
Csharp :: list of vectors c# 
Csharp :: internal working of ioc container c# 
Csharp :: convert string to float win forms 
Csharp :: O thread de chamada não pode aceder a este objecto porque existe outro thread que já o tem 
Csharp :: fix autofill issue asp.net mvc 
Csharp :: c# namespace name form1 could not be found 
Csharp :: insert button in c# 
Csharp :: get one parameter from list in an new list c# 
Csharp :: custom attribute for auth permission check .net 
Csharp :: how to turn the textbox into char in windows forms 
Csharp :: enzymes chemical factory 
Csharp :: c# panel to graphics 
Csharp :: mongodb truncation exception c# 
Csharp :: .net objects 
Csharp :: devexpress aspxdatagridview set VerticalScrollableHeight in codebehind 
Csharp :: Query Parent-GrandChild collection 
Csharp :: AsExpandable 
Csharp :: how to get src value from img tag in c# 
Csharp :: .net framework method 
Csharp :: vb.net get double item in list osf string 
Csharp :: Filter list contents with predicate (anonymous method) 
Csharp :: string with starting zero to int c# 
Csharp :: c# check if file is zero bytes 
Csharp :: c# nunit initialize variables 
Csharp :: c# parsing datetime from string irrespctive of culture 
Csharp :: how to move an object with addforce 
Csharp :: c# .net core 3.0 trying Exception The transaction log for database is full due to ACTIVE_TRANSACTION 
Csharp :: how to combine cells in closedXML 
Csharp :: alpahbet incremnet in c# 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =