This question is locked. New answers and comments are not allowed.
Hi,
I have some trouble when I am doing dynamic binding. I can add column now. But I can't edit the value in the column.
Can anyone give me some suggestion?
Below is my code.
namespace
RadControlsSilverlightApp1
{
public
partial
class
MainPage : UserControl
{
string
[] columnheaders = {
"Model"
,
"Texture"
,
"Retake"
};
ObservableCollection<MyDataRow> _data =
new
ObservableCollection<MyDataRow>();
public
virtual
ObservableCollection<MyDataRow> data
{
get
{
return
_data;
}
set
{
_data = value;
}
}
public
MainPage()
{
InitializeComponent();
for
(
int
i = 0; i < 50; ++i)
{
MyDataRow row =
new
MyDataRow();
foreach
(
string
str
in
columnheaders)
{
row[str] =
new
Decimal(1.0);
}
_data.Add(row);
}
xyz.ItemsSource = data;
}
private
void
button1_Click(
object
sender, RoutedEventArgs e)
{
Telerik.Windows.Controls.GridViewDataColumn gvc =
new
Telerik.Windows.Controls.GridViewDataColumn();
gvc.Header = textBox1.Text;
gvc.UniqueName = textBox1.Text;
gvc.DataMemberBinding =
new
Binding(textBox1.Text);
gvc.FilterMemberPath = textBox1.Text;
gvc.GroupMemberPath = textBox1.Text;
gvc.SortMemberPath = textBox1.Text;
gvc.IsReadOnly =
false
;
//gvc.DataType = typeof(Decimal);
bool
allow =
true
;
foreach
(Telerik.Windows.Controls.GridViewColumn gv
in
xyz.Columns)
{
if
(gv.Header.ToString() == textBox1.Text)
{
allow =
false
;
break
;
}
}
if
(allow)
{
foreach
(MyDataRow row
in
data)
{
row[textBox1.Text] =
new
decimal
(3.0);
}
xyz.Columns.Add(gvc);
xyz.Rebind();
}
}
}
}