Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
445
add Row to XamWebGrid from code behind
posted

private void XamWebGrid_CellExitingEditMode(object sender, ExitEditingCellEventArgs e)
        {           
            Infragistics.Silverlight.Controls.RowBase r = e.Cell.Row;           
            // Ensure using correct cell and editing has not been cancelled           
            if (e.Cell.Column.Key == "StepDescription" && !e.EditingCanceled)
            {
                ComboBox box = e.Editor as ComboBox;
                if (box.SelectedItem != null && ((ListItem)box.SelectedItem).Value!="0")
                {
                    Web.Cortex.WcfServiceReference.TestStepsProfile obj = new Web.Cortex.WcfServiceReference.TestStepsProfile(); ;
                    int StepId = Int32.Parse(((ListItem)box.SelectedItem).Value);
                    if (TestStepscollection != null && TestStepscollection.Count > 0)
                    {
                        var TestStepsMatch = TestStepscollection.Where(p => p.StepID == 6620);
                        //IEnumerable<Web.Cortex.WcfServiceReference.TestStepsProfile> qry = from c in TestStepscollection
                        //                                                                   where c.StepID == 6620
                        //                                                                   select c;                                               
                        //ObservableCollection<Web.Cortex.WcfServiceReference.TestStepsProfile> filteredClients = new ObservableCollection<Web.Cortex.WcfServiceReference.TestStepsProfile>(qry);

                        //IEnumerable<Web.Cortex.WcfServiceReference.TestStepsProfile> matches = TestS//tepscollection.Where(p => p.StepID == 6620);
                        foreach (Web.Cortex.WcfServiceReference.TestStepsProfile TestStep in TestStepsMatch)
                        {                           
                            rr.Cells["StepObjectClass"].Content = TestStep.StepObjectClass;
                            r.Cells["StepObjectClass"].Content = TestStep.StepObjectClass == null ? "" : TestStep.StepObjectClass;
                            r.Cells["StepObjectName"].Content = TestStep.StepObjectName == null ? "" : TestStep.StepObjectName;
                            //r.Cells["StepObjectAction"].Content = TestStep.StepObjectAction == null ? "" : TestStep.StepObjectAction;                           
                            r.Cells["StepID"].Content = TestStep.StepID == null ? "" : TestStep.StepID.ToString();
                            r.Cells["StepOrder"].Content = e.Cell.Row.Index + 1;                           
                            gridTransaction.Rows.Add((Row)r);                           
                            //TestStep.StepOrder = e.Cell.Row.Index + 1;
                            //TestStepList.Add(TestStep);                                   
                        }                       
                    }
                   
                    // New value is value of selected item in combo box
                    ////e.NewValue = ((ListItem)box.SelectedItem).Text;
                    box.ItemsSource = null;
                    box.SelectedItem = null;
                }
            }
        }

 

In above code I want to add the row in the grid.But as am doing

Infragistics.Silverlight.Controls.RowBase r = e.Cell.Row;  So the same row get copied again...

So anyone help me how to add new row in grid.I don't want to do it by modifying the collection object.

Parents
No Data
Reply
  • 21382
    Suggested Answer
    posted

    I am not sure what you wouldn't want to add the row to the underlying collection, as this is what the grid is going to do with the data object you provide to populate the row.

     

    But to add a new row you would call the CreateItem() method off the Rows collection where the row will belong.  You would probably want to use the CreateItem overload that allows you to pass in the dataobject that will be associated with the Row.  

     

    after that you can just add the row to the rows collection

     

    Infragistics.Controls.Grids.Row r   =grid.Rows.CreateItem();

    grid.Rows.Add(r);

Children