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

Binding problems

2 Answers 43 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Start Informatica c.a.
Top achievements
Rank 1
Start Informatica c.a. asked on 29 Aug 2016, 05:05 PM

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"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Dalessio_Logistics"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d"
             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>
            <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:RadGridView.Columns>
                    <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:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton  x:Name="btPiù" CommandParameter="{Binding Carrier}" Content="+" Click="btPiù_Click" TouchDown="btPiù_Click"  Background="#FF97DA7E" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                    <telerik:GridViewColumn Header="Disattiva" Width="80">
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton  x:Name="btMeno" CommandParameter="{Binding Carrier}" Content="{Binding Carrier}" Click="btMeno_Click" TouchDown="btMeno_Click" Background="#FFEC6F6F"/>
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </StackPanel>
        </StackPanel>
</UserControl>

 

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)
            sqlCon.Open()
 
            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)
 
            sda.Fill(dt)
            gridCarriers.ItemsSource = dt
        End Using
    End Sub

 

And this is the result:

http://prntscr.com/cbrdtd

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 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 31 Aug 2016, 10:49 AM
Hello,

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 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.

Regards,
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.
0
Start Informatica c.a.
Top achievements
Rank 1
answered on 01 Sep 2016, 12:12 PM

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.

Tags
GridView
Asked by
Start Informatica c.a.
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Start Informatica c.a.
Top achievements
Rank 1
Share this question
or