This question is locked. New answers and comments are not allowed.
Hi Everybody,
because I need to create columns at runtime I use the GridView with the very cool DataTable class. What I'm trying to accomplish is to retrieve the SelectedItems from GridView. My problem is that the SelectedItems property shows the correct number of SelectedItems but all items are Nothing. I can't find out which rows are selected and doesn't get the record back. Here is the code I use to create the GridView. It's just a reduced test code without any deep sense.
Thanks in advance,
Tobias
because I need to create columns at runtime I use the GridView with the very cool DataTable class. What I'm trying to accomplish is to retrieve the SelectedItems from GridView. My problem is that the SelectedItems property shows the correct number of SelectedItems but all items are Nothing. I can't find out which rows are selected and doesn't get the record back. Here is the code I use to create the GridView. It's just a reduced test code without any deep sense.
| Dim tester As New ObservableCollection(Of Test) |
| tester.Add(New Test With {.Name = "Peter"}) |
| tester.Add(New Test With {.Name = "Paul"}) |
| tester.Add(New Test With {.Name = "And"}) |
| tester.Add(New Test With {.Name = "Mary"}) |
| Dim rnd As Random = New Random |
| Dim table As New DataTable |
| table.Columns.Add(New DataColumn() With {.ColumnName = "Name", .DataType = GetType(String)}) |
| table.Columns.Add(New DataColumn() With {.ColumnName = "DC", .DataType = GetType(Object)}) |
| For Each test In tester |
| Dim row As DataRow = New DataRow |
| row("Name") = test.Name |
| row("DC") = test |
| table.Rows.Add(row) |
| Next |
| RadGridView.AutoGenerateColumns = False |
| RadGridView.Columns.Clear() |
| ' Name |
| Dim c = New GridViewDataColumn |
| c.Header = "Name" |
| Dim b = New Binding("Name") |
| c.DataMemberBinding = b |
| RadGridView.Columns.Add(c) |
| ' Template |
| Dim c1 = New GridViewDataColumn() |
| c1.Header = "Template" |
| c1.CellTemplate = Resources("MyTemplate") |
| b = New Binding("DC") |
| c1.DataMemberBinding = b |
| RadGridView.Columns.Add(c1) |
| RadGridView.ItemsSource = table |
| <UserControl xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="DatagridEval.MainPage" |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
| mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> |
| <UserControl.Resources> |
| <DataTemplate x:Key="MyTemplate"> |
| <StackPanel DataContext="{Binding DC}"> |
| <Button Content="{Binding Name}"></Button> |
| </StackPanel> |
| </DataTemplate> |
| </UserControl.Resources> |
| <Grid x:Name="LayoutRoot"> |
| <telerikGridView:RadGridView x:Name="RadGridView" AutoGenerateColumns="False"></telerikGridView:RadGridView> |
| </Grid> |
| </UserControl> |
Thanks in advance,
Tobias