WPF Toolkit - Binding Problem in a DataGrid Control

Hey guys, first of all, I have to say, this may seem like a lot of code, but it's easy to read. I am trying to relate some things, and I get this as a result:

http://img694.imageshack.us/f/28475988.jpg/

as you can see it looks like the number, description, row and column that were duplicated.

on my main form designer I have:

<Window x:Class="Visual_Command_Line.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Visual_Command_Line"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    Title="Visual Command Line" MinHeight="750" MinWidth="900" Loaded="Window_Loaded" Icon="/Visual_Command_Line;component/Resources/icon16x16.ico" WindowStartupLocation="CenterScreen" WindowState="Maximized" Closing="Window_Closing">
<Window.Resources>
    <local:ErrorListCollection x:Key="ErrorList" />
</Window.Resources>
                        <dg:DataGrid Name="DataGrid_ErrorList" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False" ItemsSource="{Binding Source={StaticResource ErrorList}}">
                            <dg:DataGrid.Columns>
                                <dg:DataGridTextColumn Binding="{Binding Path=GetNumber}" Header="" />
                                <dg:DataGridTextColumn Binding="{Binding Path=GetDescription}" Header="Description" Width="10*" />
                                <dg:DataGridTextColumn Binding="{Binding Path=GetLine}" Header="Line" Width="*" />
                                <dg:DataGridTextColumn Binding="{Binding Path=GetColumn}" Header="Column" Width="*" />
                            </dg:DataGrid.Columns>
                        </dg:DataGrid>
</Grid>

when the main form loads:

((ErrorListCollection)this.FindResource("ErrorList")).RenewErrorList(((TabDocument)dockManager.ActiveDocument).currentAnalizedLine);

Here is the ErrorListCollection class:

class ErrorListCollection : ObservableCollection<DebugError>
{
    public ErrorListCollection()
    {
    }

    public void RenewErrorList(AnalizedLine al) //also all lines
    {
        this.Clear();

        int currentAnalizedLine_lineNumber = al.lineNumber;

        int errNumber = 1;
        foreach (Boundaries b in al.GetBoundaries)
        {
            if (b.dataType == Boundaries.DataType.Unknown)
            {
                this.Add(new DebugError(errNumber, "d", "l", "c"));
                errNumber++;
            }
        }
    }
}

Class DebugError:

class DebugError
{
    private int Number;
    private string Description;
    private string Line;
    private string Column;

    public int GetNumber
    {
        get
        {
            return this.Number;
        }
    }

    public string GetDescription
    {
        get
        {
            return this.Description;
        }
    }

    public string GetLine
    {
        get
        {
            return this.Line;
        }
    }

    public string GetColumn
    {
        get
        {
            return this.Column;
        }
    }

    public DebugError(int Number, string Description, string Line, string Column)
    {
        this.Number = Number;
        this.Description = Description;
        this.Line = Line;
        this.Column = Column;
    }
}

How can I fix these duplicates?

Thanks to the advanced,

Dean.

+3
source share
2 answers

Try to add AutoGenerateColumn="False"

<dg:DataGrid Name="DataGrid_ErrorList" AutoGenerateColumns="False"
+5
source

Try setting AutoGenerateColumns = "False"

DebugError:

class DebugError
{
    public int Number { get; private set; }
    public string Description { get; private set; }
    public string Line { get; private set; }
    public string Column { get; private set; }

    public DebugError(int number, string description, string line, string column)
    {
        Number = number;
        Description = description;
        Line = line;
        Column = column;
    }
}
+3

Source: https://habr.com/ru/post/1795913/


All Articles