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

GridViewComboBoxColumn ItemsSource Binding

1 Answer 386 Views
GridView
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 14 Feb 2011, 06:05 PM
I am trying to do something extremely simple.
I am trying to populate a GridViewComboBoxColumn with a list of numbers ranging from 1 - 16.
This is what I have so far:

<Window x:Class="Login"
        xmlns:systhreading="clr-namespace:System.Threading;assembly=mscorlib"
        xmlns:myNamespace="clr-namespace:myNamespace"
        xmlns:primatives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="Login" Height="768" Width="1024" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <Window.Resources>
        <Style TargetType="Label">
            <Setter Property="Width" Value="100"></Setter>
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="Width" Value="100"></Setter>
        </Style>
        <myNamespace:TestUser x:Key="testUser"/ >
        <x:Array x:Key="PortValues" Type="sys:Int32">
            <sys:Int32>1</sys:Int32>
            <sys:Int32>2</sys:Int32>
            <sys:Int32>3</sys:Int32>
            <sys:Int32>4</sys:Int32>
            <sys:Int32>5</sys:Int32>
            <sys:Int32>6</sys:Int32>
            <sys:Int32>7</sys:Int32>
            <sys:Int32>8</sys:Int32>
            <sys:Int32>9</sys:Int32>
            <sys:Int32>10</sys:Int32>
            <sys:Int32>11</sys:Int32>
            <sys:Int32>12</sys:Int32>
            <sys:Int32>13</sys:Int32>
            <sys:Int32>14</sys:Int32>
            <sys:Int32>15</sys:Int32>
            <sys:Int32>16</sys:Int32>
        </x:Array>
    </Window.Resources>
    <DockPanel DataContext="{Binding Source={StaticResource testUser}}">
        <StackPanel DockPanel.Dock="Top" VerticalAlignment="Stretch" HorizontalAlignment="Center">
           <telerik:RadGridView Name="RadGridView1" ItemsSource="{Binding FooBars}">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewComboBoxColumn
                       Header="Something"
                       ItemsSource="{Binding Source={StaticResource PortValues}}" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </StackPanel>
      
    </DockPanel>
</Window>


This is my "TestUser" and "FooBar" classes that I am using for testing:

Imports System.ComponentModel
Imports System.Collections.ObjectModel
 
Public Class TestUser
 
    Private _fooBars As ObservableCollection(Of FooBar)
 
    Public Property FooBars As ObservableCollection(Of FooBar)
        Get
            Return _fooBars
        End Get
        Set(ByVal value As ObservableCollection(Of FooBar))
            _fooBars = value
        End Set
    End Property
 
    Public Sub New()
        _fooBars = New ObservableCollection(Of FooBar)
        For i As Integer = 0 To 10
            _fooBars.Add(New FooBar("FooBar" + i.ToString, i))
        Next
    End Sub
End Class
Public Class FooBar
    Public Property Value As Integer
    Public Property Name As String
 
    Public Sub New(ByVal name As String, ByVal value As Integer)
        Me.Value = value
        Me.Name = name
    End Sub
End Class


For some reason I cannot get the GridViewComboBoxColumn to populate with the "PortValues" (I can't even get it to appear).
What am I doing wrong?!?!

Thanks a lot for your help!

-Newbie

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 17 Feb 2011, 04:06 PM
Hi newbie,

Please take another look at our online documentation and demos for a reference on how you may use the GridViewComboBoxColumn. You need to expose the appropriate properties and use them through DataMemberBinding, SelectedValueMemberPath, DisplayMemberPath. So, for example, you may take a look on the implementation of the GridViewComboBoxColumn with Enum ItemsSource. 
 

All the best,
Maya
the Telerik team
Tags
GridView
Asked by
newbie
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or