Binding issue

4 posts, 0 answers
  1. Rick
    Rick avatar
    2 posts
    Member since:
    Dec 2012

    Posted 10 Feb 2013 Link to this post

    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; }
    }
          

  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 13 Feb 2013 Link to this post

    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.

  3. DevCraft banner
  4. Rick Hodder
    Rick Hodder avatar
    17 posts
    Member since:
    Jul 2004

    Posted 17 Feb 2013 Link to this post

    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


  5. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 21 Feb 2013 Link to this post

    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.

Back to Top