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.
Yes the underlaying collection is observable collection and I did the exactly by using Insert method that problem solved.
Thanks for your reply.
-Pankaj
Well if you were going to reset the ItemsSource, you would just set the grid.ItemsSource to null and then set it to the new ItemsSource.
But a better suggestion would be to add your own custom sort comparer to the grid and then have that do your sort for you, that way you aren't resetting the ItemSource all them time
I show creating a custom sort comparer here:
http://forums.infragistics.com/forums/p/41169/229540.aspx#229540
Also, what is the underlying collection type, I see you have it casted to an IEnumerable but is it a list? An ObservableCollection? If the actual type might support .InsertAt() (or is it Insert) in which case you would just be able to put your new object into your collection at the location you want
Hello Darrell,
While loading page I did
gridTransaction.ItemsSource = TestStepList; (TestStepList is ObservableCollection)
Now on XamWebGrid_CellExitingEditMode event I am adding one row to the collection and sort it by doing
IEnumerable<Web.Cortex.WcfServiceReference.TestStepsProfile> ied = from d in TestStepList where orderby d.Flag select d;
My question is how can I assign the sorted collection to the grid again ?
Please suggest...
Thanks in advance
Hello Darell,
I have the grid having column Sort Order
First time there is a blank row in the grid having sort order 0 and a combobox in one of the column.
When I select the item from combobox I need to add row on the basis of that item in the grid with sortorder = rowindex+1,But I want the blank row with sortorder 0 always at the end.
ex -like in below order I want to display the rows in grid.
SortOrder
1
2
3
0
Thats why I think it is better to add rows in grid not by modifying collection.
But still struggling to find the solution.
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);