Read csv file into wpf C#
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");
}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]);
});
}<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>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;
}
}
Also in C#:
- Title
- c# join string array
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- create object in c#
- Category
- C#
- Title
- c#if
- Category
- C#
- Title
- unity gameobjects with tag
- Category
- C#
- Title
- No context type was found in the assembly
- Category
- C#
- Title
- add new page to site c# programmatically
- Category
- C#
- Title
- linq query select top 1 c#
- Category
- C#
- Title
- unix time c#
- Category
- C#
- Title
- c# windows grab screenshot
- Category
- C#
- Title
- asign only common fields in c# object
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- what is type unity
- Category
- C#
- Title
- enums as numbers c#
- Category
- C#
- Title
- c# convert byte to char
- Category
- C#
- Title
- external font family uwp c#
- Category
- C#
- Title
- how to change player cursor c# script unity
- Category
- C#
- Title
- C# previous method
- Category
- C#
- Title
- copy a list in c# unity
- Category
- C#
- Title
- c# getasync response
- Category
- C#
- Title
- void start
- Category
- C#
- Title
- array syntax c#
- Category
- C#
- Title
- how to deactivate objects through scripts in unity
- Category
- C#
- Title
- how to detected WindowCloseEvent in other window wpf
- Category
- C#
- Title
- asp.net core mvc not triggering client side validation
- Category
- C#
- Title
- condition when a animation finishes in unity
- Category
- C#
- Title
- run async methods within a sync process
- Category
- C#
- Title
- arry in c#
- Category
- C#
- Title
- c# public static string
- Category
- C#
- Title
- idbset sqlquery
- Category
- C#
- Title
- ignore fakeiteasy
- Category
- C#
- Title
- find month number from date C#
- Category
- C#
- Title
- get user directory of file in c#
- Category
- C#
- Title
- unity c# public all codes
- Category
- C#
- Title
- movement script c#
- Category
- C#
- Title
- c# combobox datasource enum
- Category
- C#
- Title
- get waht is differnt between two arrays c#
- Category
- C#
- Title
- c# create array of int
- Category
- C#
- Title
- to list c#
- Category
- C#
- Title
- C# get all files in directory
- Category
- C#
- Title
- vb.net tostring numeric format string
- Category
- C#
- Title
- page refresh on button click in c#
- Category
- C#
- Title
- foreach c#
- Category
- C#
- Title
- c# only letters
- Category
- C#
- Title
- unity image
- Category
- C#
- Title
- is start called after dontdestroyonload
- Category
- C#
- Title
- count number of enum values C#
- Category
- C#
- Title
- send type as argument c#
- Category
- C#
- Title
- c# iterate over string
- Category
- C#
- Title
- c list add element
- Category
- C#
- Title
- wpf make size fill all grid
- Category
- C#
- Title
- Category
- C#
- Title
- vb.net yes no cancel
- Category
- C#
- Title
- c sharp if string equals
- Category
- C#
- Title
- how to copy one array value to another without reference c#
- Category
- C#
- Title
- c# return multiple value unity
- Category
- C#
- Title
- C# colours
- Category
- C#
- Title
- add text to combobox c#
- Category
- C#
- Title
- kotlin random number
- Category
- C#
- Title
- strtorime online
- Category
- C#
- Title
- get absolute url c#
- Category
- C#
- Title
- c# string methods
- Category
- C#
- Title
- C# for
- Category
- C#
- Title
- c# find element by condition
- Category
- C#
- Title
- never lose focus textbox c#
- Category
- C#
- Title
- remove from list based on condition c#
- Category
- C#
- Title
- .netstandard distinctby iqueryable
- Category
- C#
- Title
- copy to clipboard unbity
- Category
- C#
- Title
- s3 upload base64 .net core
- Category
- C#
- Title
- reverse string c#
- Category
- C#
- Title
- bitmap to byte array c#
- Category
- C#
- Title
- asp net identity add a unique fields to user
- Category
- C#
- Title
- c# list append
- Category
- C#
- Title
- c# static meaning
- Category
- C#
- Title
- double tryparse dot comma
- Category
- C#
- Title
- c# how to compare 2 dates without time
- Category
- C#
- Title
- how do i limit the amount of prefabs in unity using c# script
- Category
- C#
- Title
- convert to base64 c#
- Category
- C#
- Title
- reference to gameobject in different scene unity
- Category
- C#
- Title
- c# loop through repeater items
- Category
- C#
- Title
- unity list
- Category
- C#
- Title
- Replaced OS is obselete
- Category
- C#
- Title
- unity delete specific text in a string
- Category
- C#
- Title
- c# multiline comment
- Category
- C#
- Title
- declare string array c# without size
- Category
- C#
- Title
- c# distinct array of objects by values
- Category
- C#
- Title
- first sentence letter capital in c#
- Category
- C#
- Title
- c# MD5.Create returning nul
- Category
- C#
- Title
- C# downloadstirng download old
- Category
- C#
- Title
- percentage in c#
- Category
- C#
- Title
- get specific object in list c#
- Category
- C#
- Title
- csv to dataset c#
- Category
- C#
- Title
- c# array Reverse method
- Category
- C#
- Title
- unity key detection
- Category
- C#
- Title
- 2d object look at object
- Category
- C#
- Title
- c# max sequence contains no elements
- Category
- C#
- Title
- c# using get set methods
- Category
- C#
- Title
- unity c# change color of gameobject
- Category
- C#
- Title
- Category
- C#
- Title
- calculate impact damage + unity
- Category
- C#