How to create a sub listview inside a listview with data binding?

Hello,

I want to bind an observable collection of a List of items something like ObservableCollection<List> with that xaml code:


<ListView.ItemTemplate>


<ListView.RowHeight>

</ListView.RowHeight>
<ListView.ItemTemplate>



</ListView.ItemTemplate>


</ListView.ItemTemplate>

The binding on the sub listview is not working and I don't know what to use to solve it.
Is there a better solution than Listview to use?

Tagged:

Best Answer

Answers

  • BlondinBlondin USMember

    Sorry for the previous displayed code:

       ``<ListView x:Name="ReferencesNew" ItemsSource="{Binding RefNew}">
        ``                <ListView.ItemTemplate>
        ``                  <DataTemplate>
        ``                      <ListView ItemsSource={Binding **?**}>
        ``                         <ListView.ItemTemplate>
        ``                             <DataTemplate>
        ``                                  <TextCell Text="{Binding Ref}" Detail="{Binding Codification}"/>
        ``                             </DataTemplate>
        ``                         </ListView.ItemTemplate>
        ``                      </ListView>
        ``                  </DataTemplate>
        ``              </ListView.ItemTemplate>
        ``          </ListView>
    
  • BlondinBlondin USMember

    Hello rzee7, thanks for your answer. . I try grouped listview and it's working too with the intial object I described.

  • JoakimMnssonJoakimMnsson SEMember ✭✭

    Hi.
    I am also wondering about this one. I have nested a listview inside a listview more or less like @Blondin has done. It works great on UWP (with multiple "Main"-rows and sub-rows on some or all "mains".

    On Android if I add one "main"-row with a sub-row. However trying to add another row to the "main" gets me the Exception:

    "System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle 0x7d000045 (key_handle 0x41c3ec28)."

  • trishelwoodtrishelwood USMember ✭✭

    Hi @rzee7 ,
    I get same error as @JoakimMnsson.

    System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle 0x2c90005d (key_handle 0x428e1330).

    When I enter first item, it only displays child element and for second time, it shows above error.

    Please help.

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Hi @trishelwood

    I'm not sure what causes an issue, I'd suggest two things here as following:

    1. Try with static data as I have given an answer above.
    2. Explain about your data flow insertion, then I will be able to solve it.

    Cheers!!
    {rzee}

  • SujaBSujaB USUniversity ✭✭✭

    @rzee7 @Blondin

    Hi all,
    I have the same scenario.I need a sub list view in each cell of a list view .
    I have used the same code as mentioned above.But my issue is ,main list view is listing but in each cell of main list view only first element of sublistview is listing.

    < ListView RowHeight="160" ItemsSource="{Binding GroupList,Mode=TwoWay}" SeparatorVisibility="None" BackgroundColor="#F2F6F8" HorizontalOptions="Start">
    <ListView.ItemTemplate>


              <StackLayout Padding="10">
                <StackLayout Orientation="Horizontal" BackgroundColor="#ffffff" Padding="10" HorizontalOptions="FillAndExpand">
    
    
                  <BoxView WidthRequest="2" BackgroundColor="#D7D7D7"></BoxView>
                  <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                    <ListView RowHeight="160" BackgroundColor="#ffffff" ItemsSource="{Binding BatchList,Mode=TwoWay}" SeparatorVisibility="None"  HorizontalOptions="FillAndExpand">
                      <ListView.ItemTemplate>
                        <DataTemplate>
                          <ViewCell>
                            <StackLayout Orientation="Vertical"  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                              <Button Text="{Binding Value}" BackgroundColor="#ffff00"/>
                            </StackLayout>
    
                          </ViewCell>
                        </DataTemplate>
                      </ListView.ItemTemplate>
                    </ListView >
    
  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Hi @SujaB

    Why not use Grouping instead nested ListView ?

  • SujaBSujaB USUniversity ✭✭✭

    @rzee7
    Hi

    Could you please share some idea about grouping inside Listview? Any sample code or link

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    @SujaB You can try This see if this what you are looking for.

    Cheers
    {rzee}

  • gladglad USMember

    I wonder how to write it in the code.

  • SafakktemSafakktem USMember ✭✭

    I think @rzee7 solution not working for {Binding Path=.} child listview .It gives ParentListClass so this must be a bug.

  • sumitsisodia.9614sumitsisodia.9614 USMember ✭✭
    edited July 2017

    M. RIYAZ canyou share the code for nested listview im new user for xamarin forms pls help me .bcoz i want to this tipe of view.

    Plz Reply Fast

  • TonyTonyTonyTony USMember

    I'm also getting an error, is C# coding the only way? I was hoping to write my entire UI in XAML. Grouping seeing a bit limited, my Model has several lists:
    {
    public class Survey
    {
    public int SurveyID { get; set; }
    public string LastName{ get; set; }
    public string FirstName{ get; set; }
    public Form Form { get; set; }
    }

    public class Form
    {
    public int FormID { get; set; }
    public List Categories { get; set; }
    }

    public class Category
    {
    public int CategoryID { get; set; }
    public string Description { get; set; }
    public List Questions { get; set; }
    }

    public class Question
    {
    public int QuestionID { get; set; }
    public string Description { get; set; }
    public bool IsModified { get; set; }
    public int SelectedAnswerID { get; set; }
    public List Answers { get; set; }
    }

    public class Answer
    {
    public int QuestionID { get; set; }
    public int AnswerID { get; set; }
    public string Description { get; set; }
    }
    }

    Using @rzee7 Code, I was about to get values back for the first ListView Categories. As soon I added the Second listview for questions, I get System.NotSupportedException: Unable to activate instance of type.

  • TonyTonyTonyTony USMember

    I'm also getting an error, is C# coding the only way? I was hoping to write my entire UI in XAML. Grouping seeing a bit limited, my Model has several lists:
    {
    public class Survey
    {
    public int SurveyID { get; set; }
    public string LastName{ get; set; }
    public string FirstName{ get; set; }
    public Form Form { get; set; }
    }

    public class Form
    {
    public int FormID { get; set; }
    public List Categories { get; set; }
    }

    public class Category
    {
    public int CategoryID { get; set; }
    public string Description { get; set; }
    public List Questions { get; set; }
    }

    public class Question
    {
    public int QuestionID { get; set; }
    public string Description { get; set; }
    public bool IsModified { get; set; }
    public int SelectedAnswerID { get; set; }
    public List Answers { get; set; }
    }

    public class Answer
    {
    public int QuestionID { get; set; }
    public int AnswerID { get; set; }
    public string Description { get; set; }
    }
    }

    Using @rzee7 Code, I was able to get values back for the first ListView Categories. As soon I added the Second listview for questions, I get System.NotSupportedException: Unable to activate instance of type.

  • johntsiljohntsil Member ✭✭

    Hello i have a question !! I have a listview inside a listview like rzee7 example but i want to scroll inside inner listview.I have made the inner listview to 400 heightrequest.Is it possible ???

  • SreeeeSreeee INMember ✭✭✭✭

    @sumitsisodia.9614 said:
    M. RIYAZ canyou share the code for nested listview im new user for xamarin forms pls help me .bcoz i want to this tipe of view.

    Plz Reply Fast

    Do you complete this requirement? Do you have any sample codes for nested listview?

  • Mahesh_MMahesh_M Member ✭✭

    @sumitsisodia.9614 have you done this NestedListview?If yes can I have your inputs plz..

  • ElandaloussiishrakElandaloussiishrak USMember ✭✭

    Hi Try this Xamarin Cross Plateforme project : "ListViewWithSubListView" in my github named "github.com/ishrakland"

    to avoid the problem of nested Lists

Sign In or Register to comment.