Hello,
Is it possible to bind two comboboxes to one table with composite primary key?
Suppose one has a table MyTable with two fields (int Level, varchar2 Code) which forms composite primary key.
The corresponding entity is
public
class
MyTable
{
public
MyEnum Level {
get
;
set
;}
public
string
Code {
get
;
set
;}
}
where MyEnum is some enum.
I would like to bind two comboboxes to the list of such entities so that one combobox shows list of available items of MyEnum,
and the other one list of codes corresponding to the selected Level. Is it possible?
Thanks in advance.
Yours faithfully,
Mikhail.
<
Window
x:Class
=
"testApp.Window1"
xmlns:my
=
"clr-namespace:testApp"
xmlns:telerik
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
xmlns:telerikChart
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
xmlns:telerikCharting
=
"clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting"
Title
=
"Window1"
Height
=
"300"
Width
=
"300"
>
<
Window.Resources
>
<
my:Window1ViewModel
x:Key
=
"MyViewModel"
/>
</
Window.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
DataContext
=
"{StaticResource MyViewModel}"
>
<
telerik:RadGridView
ItemsSource
=
"{Binding Items}"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Name"
DataMemberBinding
=
"{Binding Label}"
/>
<
telerik:GridViewDataColumn
Header
=
"Values"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
telerikChart:RadChart
ItemsSource
=
"{Binding Values}"
UseDefaultLayout
=
"False"
MaxWidth
=
"200"
MaxHeight
=
"100"
>
<
telerikCharting:ChartArea
x:Name
=
"MyChartArea"
>
<
telerikCharting:ChartArea.AxisY
>
<
telerikCharting:AxisY
/>
</
telerikCharting:ChartArea.AxisY
>
<!--<
telerikCharting:ChartArea.AxisX
>
<
telerikCharting:AxisX
/>
</
telerikCharting:ChartArea.AxisX
>-->
</
telerikCharting:ChartArea
>
<
telerikChart:RadChart.SeriesMappings
>
<
telerikCharting:SeriesMapping
ChartAreaName
=
"MyChartArea"
>
<
telerikCharting:SeriesMapping.SeriesDefinition
>
<
telerikCharting:LineSeriesDefinition
LegendDisplayMode
=
"None"
/>
</
telerikCharting:SeriesMapping.SeriesDefinition
>
<
telerikCharting:SeriesMapping.ItemMappings
>
<
telerikCharting:ItemMapping
DataPointMember
=
"YValue"
/>
</
telerikCharting:SeriesMapping.ItemMappings
>
</
telerikCharting:SeriesMapping
>
</
telerikChart:RadChart.SeriesMappings
>
</
telerikChart:RadChart
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
</
Grid
>
</
Window
>
using
System.Collections.Generic;
using
System.Collections.ObjectModel;
namespace
testApp
{
class
Window1ViewModel
{
public
ObservableCollection<ItemsClass> Items {
get
;
set
; }
public
Window1ViewModel()
{
Items =
new
ObservableCollection<ItemsClass>
{
new
ItemsClass(
"Test1"
,
new
[] {0.1, 0.3, 0.5, 0.2}),
new
ItemsClass(
"Test2"
,
new
[] {0.2, 0.3, 0.5, 0.2}),
new
ItemsClass(
"Test3"
,
new
[] {0.3, 0.3, 0.5, 0.2})
};
}
}
public
class
ItemsClass
{
public
string
Label {
get
;
set
; }
public
IEnumerable<
double
> Values {
get
;
set
; }
public
ItemsClass(
string
label, IEnumerable<
double
> values)
{
Label = label;
Values = values;
}
}
}
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding ItemContent}"
>
<
telerik:GridViewDataColumn.CellEditTemplate
>
<
DataTemplate
>
<
telerik:RadAutoCompleteBox
ItemsSource
=
"{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=telerik:RadGridView, AncestorLevel=1}, Path=DataContext.ListOfItemContent}"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellEditTemplate
>
</
telerik:GridViewDataColumn
>
According to this thread, the Text property would be the SearchText property, and it has some issues:
http://www.telerik.com/community/forums/wpf/autocompletebox/setting-the-searchtext.aspx
I can reproduce the same exception with the above code. The ListOfItemContent is the list of strings in the current column. It's in the VM.
public IEnumerable<
string
> ListOfItemContent
{
get
{
return
(from i in this.MyBusinessObjects
select i.ItemContent).Distinct();
}
}
Thank you,
Gyula
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Threading.Tasks;
using System.Threading;
namespace WpfGridsPerformanceTest
{
public class MainViewModel : ViewModelBase
{
private MyDT _data;
private DelegateCommand _changeValuesCommand;
public MainViewModel()
{
_data = new MyDT();
for (int i = 0; i <
400
; i++)
{
DataRow
row
=
_data
.NewRow();
_data.Rows.Add(row);
}
}
public DataView Items
{
get
{
return _data.DefaultView;
}
}
public DelegateCommand ChangeValuesCommand
{
get
{
if (_changeValuesCommand == null)
{
_changeValuesCommand
=
new
DelegateCommand(changeValues);
}
return _changeValuesCommand;
}
}
private void changeValues()
{
Task
t
=
new
Task(() =>
{
while (true)
{
foreach (DataRow row in _data.Rows)
{
for (int i = 0; i <
row.ItemArray.Count
(); i++)
{
row[i] = (int)row[i] + 1;
}
}
Thread.Sleep(500);
}
});
t.Start();
}
}
}
<Window
x:Class
=
"WpfGridsPerformanceTest.MainWindow"
xmlns:local
=
"clr-namespace:WpfGridsPerformanceTest"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
WindowState
=
"Maximized"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
local:Telerik
/>
<!--<local:Syncfusion />-->
<!--<local:DataGrid />-->
<!--<local:ListView />-->
<
Button
Grid.Row
=
"1"
FontWeight
=
"Bold"
FontSize
=
"16"
Command
=
"{Binding ChangeValuesCommand}"
>Click to start changing values</
Button
>
</
Grid
>
</
Window
>
<
UserControl
x:Class
=
"WpfGridsPerformanceTest.Telerik"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"300"
>
<
Grid
>
<
telerik:RadGridView
ItemsSource
=
"{Binding Items}"
ShowGroupPanel
=
"False"
UseLayoutRounding
=
"False"
RowIndicatorVisibility
=
"Collapsed"
DataLoadMode
=
"Synchronous"
CanUserFreezeColumns
=
"False"
CanUserSortColumns
=
"False"
CanUserSelect
=
"True"
SelectionMode
=
"Single"
SelectionUnit
=
"FullRow"
/>
</
Grid
>
</
UserControl
>
<telerik:RadPropertyGrid x:Name="_properties" Item="{Binding Path=Workspace.SelectedItem, ElementName=PropertyPaneControl}" AutoGeneratePropertyDefinitions="False" LabelColumnWidth="Auto" />
// clear properties
for (int i = _properties.PropertyDefinitions.Count; i > 0; i--)
_properties.PropertyDefinitions.RemoveAt(i-1);