Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Toolkit - having problem Binding in the DataGrid control

First of all I must say that this may seem like a lot of code, but it is easy to read. I am trying to bind out some stuff and I get this as a result:

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

As you can see, it seems like the number, description, line, and column have been 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 I do:

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

Here's 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++;
            }
        }
    }
}

The DebugError class:

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?

like image 645
dinbrca Avatar asked Dec 29 '22 00:12

dinbrca


1 Answers

Try adding AutoGenerateColumn="False"

<dg:DataGrid Name="DataGrid_ErrorList" AutoGenerateColumns="False"
like image 164
Bala R Avatar answered Feb 01 '23 05:02

Bala R