Binding problems

3 posts, 0 answers
  1. Start Informatica c.a.
    Start Informatica c.a. avatar
    15 posts
    Member since:
    Feb 2015

    Posted 29 Aug 2016 Link to this post

    Hi, I have a problem with my gridview, I don't know why Binding works in some columns but not in other. This is my xaml:

    <UserControl x:Class="CarriersManager"
                 d:DesignHeight="500" d:DesignWidth="1100" Background="White">
        <StackPanel Margin="0,0,0,0" Height="auto" HorizontalAlignment="Stretch">
                <StackPanel x:Name="panelTitle" Height="50" VerticalAlignment="Top" DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Stretch">
                    <telerik:Label Content="Gestione operatori:"/>
                <StackPanel x:Name="spContent">
                <telerik:RadGridView x:Name="gridCarriers"  AutoGenerateColumns="False" CanUserInsertRows="False" CanUserDeleteRows="False" RowIndicatorVisibility="Collapsed" IsFilteringAllowed="True"
                ShowGroupPanel="False" IsReadOnly="False" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" SelectionMode="Single"
                CanUserReorderColumns="False" FontFamily="Source Sans Pro Semibold" FontSize="14" GridLinesVisibility="Horizontal" RowHeight="45">
                        <telerik:GridViewDataColumn x:Name="Carrier" UniqueName="Carrier" Header="Carrier" IsReadOnly="True" Width="150" DataMemberBinding="{Binding Carrier}"/>
                        <telerik:GridViewDataColumn x:Name="CompanyName" Header="CompanyName" IsReadOnly="True" DataMemberBinding="{Binding CompanyName}" Width="*"/>
                        <telerik:GridViewCheckBoxColumn Header="Attivo" Width="100" DataMemberBinding="{Binding Attivo}" IsReadOnly="True"/>
                        <telerik:GridViewColumn Header="Attiva" Width="80">
                                    <telerik:RadButton  x:Name="btPiù" CommandParameter="{Binding Carrier}" Content="+" Click="btPiù_Click" TouchDown="btPiù_Click"  Background="#FF97DA7E" />
                        <telerik:GridViewColumn Header="Disattiva" Width="80">
                                    <telerik:RadButton  x:Name="btMeno" CommandParameter="{Binding Carrier}" Content="{Binding Carrier}" Click="btMeno_Click" TouchDown="btMeno_Click" Background="#FFEC6F6F"/>


    this is my vb:

    Private Sub UserControl_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
            Dim dt As New DataTable
            Using sqlCon = New SqlConnection(ConnectionStringRemote)
                Dim cmd = New SqlCommand("", sqlCon)
                cmd.CommandText = "SELECT MA_Carriers.Carrier, MA_Carriers.CompanyName, ISNULL(STRT_CarriersManager.Activated,0) AS Attivo
    FROM            STRT_CarriersManager RIGHT OUTER JOIN
    MA_Carriers ON STRT_CarriersManager.Carrier = MA_Carriers.Carrier WHERE MA_Carriers.Disabled=0"
                Dim sda = New SqlDataAdapter(cmd)
                gridCarriers.ItemsSource = dt
            End Using
        End Sub


    And this is the result:

    As you can see the content of the green button is empy, and also the commandparameter is empty when I try to retrieve it. Can you help me please? 


    Thank you


  2. Dilyan Traykov
    Dilyan Traykov avatar
    1212 posts

    Posted 31 Aug 2016 Link to this post


    As you've explicitly set the Content of the green button and the red button seems to be lacking such, I assume you meant red rather than green in your last reply. The behavior you've described does seem odd, though. I've tried to reproduce it in a sample project, but was, unfortunately, unable to do so.

    Could you please have a look at the attached project and let me know if I'm missing something important? Thank you in advance for your cooperation on the matter.

    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. Start Informatica c.a.
    Start Informatica c.a. avatar
    15 posts
    Member since:
    Feb 2015

    Posted 01 Sep 2016 Link to this post

    Hi Dilyan, 

    this line you wrote in my other open thread was the key: "On a side note, please bear in mind that when a DataTable is needed as a source collection of RadGridView, it is recommended to use its DefaultView property as specified in the following article.

    gridCarriers.ItemsSource = dt.DefaultView"

    I added .DefaultView and all the binding problems are gone, now when I read the commandParameter I can retrieve the values correctly, before they where all "Nothing". 


    Thank you very mutch.

Back to Top