Maui.net Combobox

1 Answer 210 Views
ComboBox
Renjith
Top achievements
Rank 1
Renjith asked on 22 Mar 2023, 10:03 AM

Unable to set selected item text propery from viewmodel unless IsEditable="True" but not IsEditable="{Binding boolvar}"

The below code will show the text property but editable. How to make the combo box non-editable and programmatically set the selected item and selected text

                <telerik:RadComboBox  x:Name="MAccountHead" DisplayMemberPath="{Binding SelectedType.TypeDesc, Mode=TwoWay}"  SelectedItem="{Binding SelectedType, Mode=TwoWay}"
                                   HighlightTextColor="Blue" ItemsSource="{Binding Typ}" Text="{Binding SelectedType.TypeDesc, Mode=TwoWay}"
                                HeightRequest="45"  PlaceholderColor="LightGray" Placeholder="Main Head"
                                  Grid.Row="4" Grid.Column="1" BorderThickness="0,0,0,1"  IsEditable="True">
                    <telerik:RadComboBox.Triggers>
                        <DataTrigger TargetType="telerik:RadComboBox"
                                 Binding="{Binding FormVal.TypeErrorVisible}"
                                 Value="true">
                            <Setter Property="BackgroundColor" Value="Bisque"/>
                        </DataTrigger>
                    </telerik:RadComboBox.Triggers>
                </telerik:RadComboBox>

 

1 Answer, 1 is accepted

Sort by
0
Maria
Telerik team
answered on 27 Mar 2023, 08:52 AM

Hello Renjith,

Thank you for the code snippet.

I tested this on my side and the code seems to work as expected. One possible cause for the behavior you described that I could think of, would be if the SelectedItem does not match an instance in the source collection.

For example, `this.SelectedItem = this.Items[2]` would work but `this.SelectedItem = new City() { Name = "London" }` will only work if the Equals method of the City class is overridden so that two objects with the same Name property value are designed to be equal.

I am sending you the sample project I set up and used for the testing. Could you please modify it so I can try to reproduce the unwanted behavior on my side? If it's more convenient, you could send me a sample project on your side so I can see the setup from the ViewModel.

Thank you in advance for your cooperation on the matter. I am looking forward to your reply.

Tags
ComboBox
Asked by
Renjith
Top achievements
Rank 1
Answers by
Maria
Telerik team
Share this question
or