Created
July 9, 2020 09:52
-
-
Save mouadcherkaoui/6ac9c4aa29143b57448faf5a62ec1288 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Serial Number | Company Name | Employee Markme | Description | Leave | |
---|---|---|---|---|---|
9788189999599 | TALES OF SHIVA | Mark | mark | 0 | |
9780099578079 | 1Q84 THE COMPLETE TRILOGY | HARUKI MURAKAMI | Mark | 1 | |
9780198082897 | MY KUMAN | Mark | Mark | 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="DataGridCheckBox.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:local="clr-namespace:DataGridCheckBox" | |
mc:Ignorable="d" | |
Title="MainWindow" Height="450" Width="800"> | |
<Window.DataContext> | |
<local:MainWindowViewModel></local:MainWindowViewModel> | |
</Window.DataContext> | |
<Grid> | |
<DataGrid AutoGenerateColumns="false" ItemsSource="{Binding Table}"> | |
<DataGrid.Columns> | |
<DataGridTextColumn Header="Serial Number" Binding="{Binding Serial_Number}"></DataGridTextColumn> | |
<DataGridCheckBoxColumn Header="Leave" Binding="{Binding Leave}"></DataGridCheckBoxColumn> | |
</DataGrid.Columns> | |
</DataGrid> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.IO; | |
using System.Text; | |
using System.Linq; | |
namespace DataGridCheckBox | |
{ | |
public class MainWindowViewModel | |
{ | |
public DataTable Table { get; set; } | |
public MainWindowViewModel() | |
{ | |
// recuperer les ligne du fichier csv | |
string[] enregistrements = File.ReadAllLines(Path.GetFullPath("demo.csv")); | |
// instancier une nouvelle data table | |
Table = new DataTable(); | |
// recuperer les entetes de colonnes | |
string[] entetes = enregistrements[0].Split(','); | |
// ajouter les entetes a l'ensemble des colonnes de la grid | |
foreach (string t in entetes) | |
{ | |
Table.Columns.Add(t.Replace(" ", "_"), typeof(string)); | |
} | |
// recuperation d'enregistrements | |
for (int i = 1; i < enregistrements.Length; i++) | |
{ | |
var values = enregistrements[i].Split(','); | |
object[] t = new object[] { values[0], values[1], values[2], values[3], Int32.Parse(values[4]) == 1 ? true : false }; | |
Table.Rows.Add(t); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment