Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Programatically insert rows

Sort Posts: Previous Next
  •  05-10-2008, 4:27 AM Post no. 12146

    Programatically insert rows

    Hi.

    I need to programatically insert rows and not use binding.

    I have tried to do this:

    for (int r = 0; r < Properties.Settings.Default.RowsPreviewCount && r < selectedDataTable.Rows.Count; r++)
                    {
                        Xceed.Wpf.DataGrid.DataRow xceedRow = new Xceed.Wpf.DataGrid.DataRow();
                        dataGridControl.Items.Add(xceedRow);
                        DataRow dataRow = selectedDataTable.Rows[r];
                        for (int i = 0; i < dataRow.StringData.Length; i++)
                        {
                            Xceed.Wpf.DataGrid.Cell cell = new Xceed.Wpf.DataGrid.Cell();
                            Label label = new Label();
                            label.Content = dataRow.StringData(i);
                            cell.Content = label;
                            xceedRow.Cells.Add(cell);
                        }
                        for (int i = 0; i < dataRow.NumericData.Length; i++)
                        {
                            Xceed.Wpf.DataGrid.Cell cell = new Xceed.Wpf.DataGrid.Cell();
                            cell.Content = dataRow.NumericData(i);
                            xceedRow.Cells.Add(cell);
                        }
                    }

    But the Xceed DataGrid shows empty rows. I guess i'm doing something wrong.

    If rows can't be programatically inserted is there a way to bind from two collections, like collection1 + collection2 must fit in a single row.

    Thanks.
     

  •  05-12-2008, 8:09 AM Post no. 12161 in reply to 12146

    Re: Programatically insert rows

    The problem is that you are trying to insert containers (Xceed.Wpf.DataGrid.DataRow) rather than data items. That said, what I suggest you do is bind the grid to a DataGridCollectionView that is bound to an ObservableCollection that contains the data items you want to display in your grid. You can then add the items directly to the observable collection. Take a look at the Providing Unbound Data example in the documentation for more information.

    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.