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

Binding issue

3 Answers 53 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 11 Feb 2013, 02:11 AM
Hi,
I'm binding a radcombobox in a radgridview. It is not throwing a binding error, but it is not populating from the Remarks property

 <telerik:GridViewDataColumn Header="Remarks" UniqueName="colRemarks" IsFilterable="False" IsSortable="False" IsReadOnly="False" Width="430">
      <telerik:GridViewDataColumn.CellTemplate>
         <DataTemplate>
            <telerik:RadComboBox SelectedValue="{Binding Model.Remarks, Mode=TwoWay}" ItemsSource="{StaticResource NotamRemarkList}" IsEditable="True"/>
         </DataTemplate>
   </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

Here are the classes:

 public class NotamViewModel
    {

        // extras that are not stored in DB, but rather, come from an aggregation

        [DataMember]
        public string NewStatus { get; set; }

        [DataMember]
        public Notam Model { get; set; }

        [DataMember]
        public string NotamGroup { get; set; }

        [DataMember]
        public int NotamCount { get; set; }

        [DataMember]
        public DateTime? EarliestNotamDepartureTime { get; set; } // min_dep_datetime

        [DataMember]
        public string RadioButtonGroupName { get; set; }
    }

public class Notam

 {
        #region Properties

               [DataMember]
        public string Remarks { get; set; }
        
        [DataMember]
        public string TripNumber { get; set; }

        [DataMember]
        public string ArrivalDeparture { get; set; }
}
      

3 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 13 Feb 2013, 01:12 PM
Hi Rick,

It seems that there is a binding issue with the SelectedValue in the code snippet you provided to us. Note that in some cases when you create an new object of the same type that is in the ItemsSource of the ComboBox with the exact same details and bind it to the SelectedValue it actually is not the same item as the one in the ItemsSource and they do not match, that is probably why the binding is not working.

I created and attached a sample project for you showing an approach on how to bind a custom GridViewDataColumn and the built-in GridViewComboBoxColumn in the GridView control.

Hope this is helpful.

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rick
Top achievements
Rank 1
answered on 18 Feb 2013, 02:19 AM
Hi Vladi,

Thanks for the example,

To see the problem that I'm experiencing

if you add the following column

<telerik:GridViewDataColumn>
   <telerik:GridViewDataColumn.CellTemplate>
       <DataTemplate>
           <Button Click="Button_Click"/>
       </DataTemplate>
   </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

 private void Button_Click(object sender, RoutedEventArgs e)
{
   Debug.WriteLine(((Employee)((Button)sender).DataContext).SelectedItem);
}

Run the app,

Press the button in the first row, and you will see Item 0 written out to the debug window.

So far, so good.

Now In the choose the rightmost combobox, and type Rick into it, then press the button in the same row

null is written out to the debug window.

I want Rick written out to the debug window.

Can you help me do this?

Thanks


0
Konstantina
Telerik team
answered on 21 Feb 2013, 11:19 AM
Hello Rick,

Thank you for the clarification.

The SelectedValue in the ComboBox is different than the Text value which is displayed in the TextBox of the ComboBox. In order the SelectedValue to change the written text in the TextBox should match one of the items of the ComboBox. If not, it stays only as a value of the Text property, and that is why you are receiving null when debugging.
If you want the new value to be set as SelectedValue in the ComboBox you will have to add it first to the ItemsSource and then select it.

Hope this info helps.

Kind regards,
Konstantina
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ComboBox
Asked by
Rick
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Rick
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or