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

[Solved] GridView SelectedItem null inside RadTabItem

2 Answers 165 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.
charles
Top achievements
Rank 1
charles asked on 28 Oct 2010, 06:37 AM
Hi,

I have 3 RadTabItem on a navigation page that each has a GridView in it.
Let's say that RadTabItem A has GridView A, and so on.
The data for the gridviews are populated from web service on Loaded event and then set to each GridViews.

RadTabItem A is the first tab to appear on the page and I can set the value for GridViewA.SelectedItem from code behind.
This works as expected, but when I set the GridViewB.SelectedItem for RadTabItem B, it will always be set to null.
I've made sure that the itemssource has value & assigned to GridViewB (I can see the content of GridView B when RadTabItem B is selected but can't see the selectedItem on it).
If I select RadTabItem C and go back to RadTabItem B, then I can the selectedItem on GridView B.

Code snippet:
<telerik:RadTabControl>
  <telerik:RadTabItem x:Name="RadTabItemA">
    <telerik:RadTabItem.Content>
      <telerik:RadGridView x:Name="RadGridViewA">
      </telerik:RadGridView>
    </telerik:RadTabItem.Content>
  </telerik:RadTabItem>
  <telerik:RadTabItem x:Name="RadTabItemB">
    <telerik:RadTabItem.Content>
      <telerik:RadGridView x:Name="RadGridViewB">
      </telerik:RadGridView>
    </telerik:RadTabItem.Content>
  </telerik:RadTabItem>
  <telerik:RadTabItem x:Name="RadTabItemC">
    <telerik:RadTabItem.Content>
      <telerik:RadGridView x:Name="RadGridViewC">
      </telerik:RadGridView>
    <telerik:RadTabItem.Content>
  </telerik:RadTabItem>
</telerik:RadTabControl>

When I set the RadTabItem B as the selected Tab on first load, this works for GridView B (I can see the highlighted selectedItem) but the other tab don't seem to have selectedItem on their respective GridView when I click on RadTabItem A or C.

Is it not possible to set selectedItem for GridView on the tab that is not selected?
If it is, then how come when I click on Tab B, the selectedItems for GridView B is still null? (I've tried to re-set the selectedItem during RadTabControl_SelectionChanged event as well).

I did a trace and it seems GridView B.HasItems is set to true after RadTabItem C is selected (selection changed) eventhough I've set the ItemsSource for each GridView on first load.
The flow would be RadTabItem A (default 1st load) -> RadTabItem B (no SelectedItems on GridView B) -> RadTabItem C (right now I can see that GridViewB.HasItems is set to true) -> RadTabItem B (I can now see the selectedItem for GridView B)

I may be doing something wrong here but not sure where.

2 Answers, 1 is accepted

Sort by
0
charles
Top achievements
Rank 1
answered on 29 Oct 2010, 04:57 AM
After digging around and trying out most of the events for gridview and radtabcontrol, apparently I need to set the GridViewB.SelectedItem on DataLoaded event and this works fine, previously I set the selected item after I set the ItemSource for each GridView.
0
Maya
Telerik team
answered on 29 Oct 2010, 01:52 PM
Hello charles,

I am glad you find an appropriate solution for your application. Furthermore, in case you require the first item of your grid to be the selected one, you may set the property of RadGridView - IsSynchronizedWithCurrentItem to "True".
Let me know if you need any further assistance.


Regards,
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
Tags
GridView
Asked by
charles
Top achievements
Rank 1
Answers by
charles
Top achievements
Rank 1
Maya
Telerik team
Share this question
or