This is a migrated thread and some comments may be shown as answers.

[Solved] Complex gridview

8 Answers 189 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Keith Stephens
Top achievements
Rank 1
Keith Stephens asked on 14 Oct 2010, 04:48 PM
I have a parent gridview with 2 childrern.
In my parent when it goes to edit mode, my second cell is a drop down of 3 leter port codes "RAB" when the user select a port code in my SelectionChanged event I get the index of the gridview and populate cell 3 and 4 from the object that populated the 3 letter port code drop down.
SelectionChanged event for parent grid.
private void rcboChgCode_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
  
            //int CurIdx = gdvTshipRates.Items.IndexOf(gdvTshipRates.CurrentItem);
            int CurIdx;
  
            RadComboBox cmbo = (RadComboBox)sender;
            var row = cmbo.ParentOfType<GridViewRow>();
  
            if (row != null)
            {
                AATshipAgree club = row.DataContext as AATshipAgree;
                CurIdx = gdvTshipRates.Items.IndexOf(club);
  
                if (CurIdx >= 0)
                {
                    if (e.AddedItems != null && e.AddedItems.Count == 1)
                    {
  
                        LocationCodeObject lCode = e.AddedItems[0] as LocationCodeObject;
                        AAgentAgreement[CurIdx].DestPortNum = lCode.Loc_Num;
                        AAgentAgreement[CurIdx].DestPortName = lCode.Loc_Name;
                        AAgentAgreement[CurIdx].DestPortCountry = lCode.Loc_Country;
  
                    }
  
                    //gdvTshipRates.Rebind();
  
                }
                else //It's a new row.
                {
                    //a new item
                    if (e.AddedItems.Count != 0)
                    {
                        CurIdx = AAgentAgreement.Count - 1;
                        LocationCodeObject lCode = e.AddedItems[0] as LocationCodeObject;
                        AAgentAgreement[CurIdx].DestPortNum = lCode.Loc_Num;
                        AAgentAgreement[CurIdx].DestPortName = lCode.Loc_Name;
                        AAgentAgreement[CurIdx].DestPortCountry = lCode.Loc_Country;
  
                    }
                }
  
            }
  
  
  
        }
Now in my second child gridview I want the same functionality, but this time the drop down will be the title field and on selection of this I want the rest of the cells in the second child gridview to be updated.
This is were I am having some difficulties. This is what I have so far in my selectionChanged event, I think my problem is I can not seem to get the correct Index.
private void rcboRateNotes_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            //int CurIdx = gdvTshipRates.Items.IndexOf(gdvTshipRates.CurrentItem);
            int CurIdx;

            RadComboBox cmbo = (RadComboBox)sender;
            var row = cmbo.ParentOfType<GridViewRow>();
            var childGrids = this.gdvTshipRates.ChildrenOfType<GridViewDataControl>();
            var item = childGrids[0].SelectedItem;
            var item2 = childGrids[1].SelectedItem;

            var selectedRow = (GridViewRow)this.gdvTshipRates.ItemContainerGenerator.ContainerFromItem(this.gdvTshipRates.SelectedItem);
            var childGrid = selectedRow.ChildrenOfType<GridViewDataControl>().FirstOrDefault();
            var childGridcnt = selectedRow.ChildrenOfType<GridViewDataControl>().Count;

         
            //if (childGrid != null)
            //{
            //    childGrid.Columns[1].IsVisible = false;
            //}

            //if (row != null)
            //{
            //    TShipNote club = row.DataContext as TShipNote;
                               
            //   // AllRateNotes club = row.DataContext as AllRateNotes;

            //    CurIdx= gdvTshipRates.Items.IndexOf(club);


            //    if (CurIdx >= 0)
            //    {
            //        if (e.AddedItems != null && e.AddedItems.Count == 1)
            //        {

            //            RateNotes lCode = e.AddedItems[0] as RateNotes;

            //            AllRateNotes2[CurIdx].NoteNum = lCode.NoteNum;
            //            AllRateNotes2[CurIdx].SecLevel = lCode.SecLevel;
            //            AllRateNotes2[CurIdx].NoteLevel = lCode.NoteLevel;
            //            AllRateNotes2[CurIdx].NoteClass = lCode.NoteClass;
            //            AllRateNotes2[CurIdx].NoteBody = lCode.NoteBody;


            //        }

            //        //gdvTshipRates.Rebind();

            //    }
            //    else //It's a new row.
            //    {
            //        //a new item
            //        if (e.AddedItems.Count != 0)
            //        {
            //            CurIdx = AAgentAgreement.Count - 1;
            //            RateNotes lCode = e.AddedItems[0] as RateNotes;
                                            
            //            AllRateNotes2[CurIdx].NoteNum = lCode.NoteNum;
            //            AllRateNotes2[CurIdx].SecLevel = lCode.SecLevel;
            //            AllRateNotes2[CurIdx].NoteLevel = lCode.NoteLevel;
            //            AllRateNotes2[CurIdx].NoteClass = lCode.NoteClass;
            //            AllRateNotes2[CurIdx].NoteBody = lCode.NoteBodyLines2;

            //        }
            //    }

            //}
        }

         

    }
And the attached file is what my screen looks like.
Hope this is enough details for some help or advice.
KS.

8 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 18 Oct 2010, 08:55 AM
Hi Keith Stephens,

If I understand you correctly, you want to update the values inside the cells of a row when the value of the ComboBox on the same row is changed. So, you may try to get the row (using ParentOfType<> method for that ComboBox). Once you find it, you can use the ItemContainerGenerator.ItemFromContainer(row) and get the item. Afterwards, all you need to do is to update the value of this item, using its Properties.
Another possibility is to get the SelectedItem, cast it to the target type and again update the values of the properties.
Let me know if this meets your requirements.
 

Best wishes,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Keith Stephens
Top achievements
Rank 1
answered on 18 Oct 2010, 01:46 PM
Hello Maya,

What you have said sounds correct, but can you provide an example?  I am not sure how to use or use correctly the ParentOfType<>  or the ItemContainerGenerator.ItemFromContainer(row) .

Thanks,
KS
0
Accepted
Maya
Telerik team
answered on 18 Oct 2010, 02:32 PM
Hi Keith Stephens,

I am sending you a sample project illustrating how to implement either of the proposed solution.
 

Best wishes,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Keith Stephens
Top achievements
Rank 1
answered on 18 Oct 2010, 03:42 PM
Sorry Maya,

I am still not getting it. In my parent grid I am able to set my cells/object as needed calling the rcboChgCode_SelectionChanged,
But where my problem now lies in in the second child grid, x:name is childGrid2.

In my rcboRateNotes_SelectionChanged for this grid I do not see my childGrid2 control object to get.

Your example just shows one grid.  And this is working for me if I am using the parent grid.
I think I am almost there in my rcboRateNotes_SelectionChanged.

Also your example changes all the rows, I only want the one row changed. So when you change the country to Spain, Adam's name shows in the name cell/field.

KS.
0
Keith Stephens
Top achievements
Rank 1
answered on 18 Oct 2010, 04:44 PM
I think I got it with this code.
private void rcboRateNotes_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
       {
           //int CurIdx = gdvTshipRates.Items.IndexOf(gdvTshipRates.CurrentItem);
           int CurIdx;
           RadComboBox cmbo = (RadComboBox)sender;
           var row = cmbo.ParentOfType<GridViewRow>();
           GridViewRow parentRow = cmbo.ParentOfType<GridViewRow>();
           var childGrids = this.gdvTshipRates.ChildrenOfType<GridViewDataControl>();
           var item = childGrids[0].SelectedItem;
           var item2 = childGrids[1].SelectedItem;
           //var selectedRow = (GridViewRow)this.gdvTshipRates.ItemContainerGenerator.ContainerFromItem(this.gdvTshipRates.SelectedItem);           
             
           //var childGrid = selectedRow.ChildrenOfType<GridViewDataControl>().FirstOrDefault();
           //var childGridcnt = selectedRow.ChildrenOfType<GridViewDataControl>().Count;
           //TShipNote            
             
         // AllRateNotes oldvalues =  childGrids[1].ItemContainerGenerator.ItemFromContainer(parentRow) as AllRateNotes;  
           TShipNote oldvalues = childGrids[1].ItemContainerGenerator.ItemFromContainer(parentRow) as TShipNote;  
    
           if (parentRow != null)
           {
                              
                RateNotes lCode = e.AddedItems[0] as RateNotes;
                 oldvalues.InvNum = lCode.NoteNum;
                 oldvalues.NoteNum = lCode.NoteNum;
                 oldvalues.SecLevel = lCode.SecLevel;
                 oldvalues.NoteLevel = lCode.NoteLevel;
                 oldvalues.NoteClass = lCode.NoteClass;
                 oldvalues.NoteBodyLines2 = lCode.NoteBody;
           } //    else //It's a new row.
           //{
           //    //a new item
           //    if (e.AddedItems.Count != 0)
           //    {
           //        CurIdx = AAgentAgreement.Count - 1;
           //        RateNotes lCode = e.AddedItems[0] as RateNotes;
           //        AllRateNotes2[CurIdx].NoteNum = lCode.NoteNum;
           //        AllRateNotes2[CurIdx].SecLevel = lCode.SecLevel;
           //        AllRateNotes2[CurIdx].NoteLevel = lCode.NoteLevel;
           //        AllRateNotes2[CurIdx].NoteClass = lCode.NoteClass;
           //        AllRateNotes2[CurIdx].NoteBody = lCode.NoteBodyLines2;
           //    }
           //}
            
            
       }
0
Keith Stephens
Top achievements
Rank 1
answered on 19 Oct 2010, 07:44 PM
Another question on this.  How can I get this to work when the user adds a new item?

Thanks,
KS
0
Maya
Telerik team
answered on 20 Oct 2010, 04:54 PM
Hello Keith Stephens,

Depending on your specific requirements, you may try to set default values for the newly-added row either in the constructor of the corresponding class or when handling the BeginningEdit/ AddingNewItem events. 
In case none of this satisfies your necessities, I would ask you for more details about the behavior you expect when inserting new item.
 

All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Keith Stephens
Top achievements
Rank 1
answered on 03 Nov 2010, 06:54 PM
Resolved.
thx.
Tags
GridView
Asked by
Keith Stephens
Top achievements
Rank 1
Answers by
Maya
Telerik team
Keith Stephens
Top achievements
Rank 1
Share this question
or