locked
How to set Combobox Treeviewlist selected item in Silverlight RRS feed

  • Question

  • Hi, 

    I loaded combobox values in Treeview style as shown below using following code

    <ComboBox x:Name="Combobox1" Width="140" Height="20" Grid.Column="1" Style="{StaticResource ComboboxStyle}" HorizontalAlignment="Left">

                            <ComboBox.Items>

                                <controls:TreeView x:Name="treeSelection"  >
                                
                                  
                                    
                                </controls:TreeView>

                            </ComboBox.Items>

                            </ComboBox>


                   
                    Dim madded As Boolean = False
                    Dim mTreeViewItem As New TreeViewItem
                    For Each row In Me.DataSet.Tables("GetIssueCodes").Rows


                        With mTreeViewItem
                            If Not madded Then
                                .Header = row("ELMTITLE")
                                treeSelection.Items.Add(mTreeViewItem)
                            End If
                            madded = True
                            Dim mTreeview As New TreeViewItem
                            mTreeview.Header = row("ELMTITLE")
                            .Items.Add(mTreeview.Header)
                        End With

     Next

    iam able to load values but when i select the value from the list selected value is not showing in dropdown as a selected value . please suggest how to show selected value in dropdown of treeview list.

     


    Krishna

    Monday, August 22, 2016 2:53 PM

All replies

  • Hi Dkrishna,

    According to your code snippet, you need to add a SelectedItemChanged event for your TreeView control. Then when the selected item changed, you need to assign the value to the ComboBox's SelectedItem.

    And following link provide a sample custom ComboboxTreeview class, which overwrite the Combobox control. It is more applicable. Hope it can help you.

    https://1drv.ms/u/s!AkHKK8SV6besg2KucrCkifVXtudO


    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, August 24, 2016 7:41 AM
    Moderator
  • I tried same thing i added SelectedItemChanged event to Treeview Control and tried to assign Combobox selectedItem but when iam trying it is not assigning value to Combobox selecteditem due to itemssource is nothing for Combobox.

    Krishna

    Wednesday, August 24, 2016 10:45 AM
  • Hi Dkrishna,

    Could you please share a sample project about how do you implement your ComboboxTreeView to OneDrive and share a public link here?

    And I think the sample project that I provided in my first reply has implement your requirement. I suggest you try that way to implement the ComboboxTreeView.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, August 25, 2016 7:21 AM
    Moderator
  • Thanks for the reply,

    If i want to bind data to Combobox using some datatable how can i bind it ? Can you please your ideas to it .

    Using your sample i created as dll for control and using it my silverlight application. The code which is present in Mainpage.cs need to implemented in my project to bind data to combobox . in this case how i can bind it with datatable ?

    AND also using your sample 

    is it possible to set selecteditem as  item 1.1 Item 2.2 Item 3.1

    Right now it will set any of the one level as selected item . Can you please help on modifying this selected item.

    Thanks

    Krishna


    Krishna

    Thursday, August 25, 2016 7:55 AM
  • Hi Krishna,

    If you want to use datatable as datasource for the combobox, you could change the Item property type to DataTable. So you need to modify the source code.

    >> is it possible to set selecteditem as  item 1.1 Item 2.2 Item 3.1

    Do you mean you want to implement multiple selected items? As far as I know, the default action for combobox could choose one item. The sample I provided is inherits from Combobox, so it could not choose multiple items everytime.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 1, 2016 7:09 AM
    Moderator