locked
DataGrid WPF C# I can't fill with code nor edit in runtime RRS feed

  • Question

  • Hello,

    Some months ago I got very good help from this forum, about WPF. (I couldn't find WPF forum then I posted here)

    I have this DataGrid inside a Window, that I want to use to edit rows that have a previous value, there are 2 cells string, for a data and a number.

    <DataGrid Name="TelsGrid" Grid.Column="3" Grid.Row="3" Grid.ColumnSpan="8" Width="320" Height="160" 
                ColumnHeaderHeight="36" RowHeight="36" RowHeaderWidth="36" HorizontalAlignment="Left" 
                VerticalScrollBarVisibility="Visible" FontSize="18" AutoGenerateColumns="False" 
                EnableRowVirtualization="True" CanUserAddRows="True" CanUserDeleteRows="True"
                SelectionMode="Single" SelectionUnit="CellOrRowHeader" GridLinesVisibility="All"
                BeginningEdit="OnBeginEdit" IsReadOnly="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Título" Width="100">
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Nro. de Tel." Width="220">
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>

    I want to fill that with this code (the previous values), that is inside a method, there are no compiler error at any place.

    foreach (TelData data in obj.Tels.PhoneNbrs)
    {
        TelsGrid.Items.Add(new object[] { data.Title, data.Number });
    }
    And in runtime I see the rows (Items) are added, but there is no text in the cells nor can I edit them, those are the 2 problems.

    Thank you in advance for your help

    Regards

    Pablo

    • Moved by CoolDadTx Thursday, October 22, 2020 8:11 PM WPF related
    Thursday, October 22, 2020 7:20 PM

All replies

  • Hello,

    You might consider seeing in the following might provide an alternate way to work with a DataGrid.

    Otherwise go here to ask your question as the WPF forum has been retired.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, October 22, 2020 7:29 PM