DaveDev
DaveDev

Reputation: 42195

How to get a WPF datagrid to display characters correctly?

I have a simple datagrid that I'm binding to a CSV file, but the data is being displayed incorrectly as follows.

enter image description here

How can I change it so the '?' characters are displayed as ' ' (space) characters as they're supposed to be?

The grid is very simply defined as:

<Grid>
    <DataGrid AutoGenerateColumns="True" FontFamily="Lucida Sans Unicode"
          ItemsSource="{Binding}">
    </DataGrid>
</Grid>

And I populate the grid as follows:

    public MainWindow()
    {
        InitializeComponent();

        string startupPath = System.IO.Directory.GetCurrentDirectory();
        DataContext = TranslationService.ReadFile(Path.Combine(startupPath, "translations.csv"));
    }

public static class TranslationService
{
    public static List<TagEntry> ReadFile(string filepath)
    {
        var lines = File.ReadAllLines(filepath);

        var data = from l in lines.Skip(1)
                   let split = l.Split(',')
                   select new TagEntry
                   {
                       Tag = split[0],
                       English = split[1],
                       Irish = split[2],
                   };

        return data.ToList();
    }
}

Upvotes: 0

Views: 766

Answers (1)

Tchadizman
Tchadizman

Reputation: 26

Have you try to force the encoding ?

Use :

File.ReadAllLines(filepath, Encoding.UTF8);

Upvotes: 1

Related Questions