Hi!
I'm trying to implement the Copy mechanism, but I have a serious problem.
My Datagrid is bound to a ObservableCollection<MyRow>. Here is the MyRow class
As you can see, the columns are created dynamically, because the MyRow object can hold an arbitrary number of values (so that number of columns would have to be made). The columns are generated for each String in ColumnNames and the values are bound by using the parameterized ValueConverter.
However, when I try to Copy (CTRL+C), this is what I get.
Value1 is the name contained in the List<String> ColumnNames. That part is ok. However, I don't get the data (which are the decimal values, like 0.242524312), but instead I get the class name.
What can I do to make the copy operation retain the values in the bound property of the MyRow object instead of its class name (I guess it calls the ToString() method on whatever is inside).
I'm trying to implement the Copy mechanism, but I have a serious problem.
My Datagrid is bound to a ObservableCollection<MyRow>. Here is the MyRow class
public
class
MyRow
{
public
List<
string
> ColumnNames {
get
;
set
; }
public
List<
decimal
?> Values {
get
;
set
; }
public
String TimeStamp {
get
;
set
; }
public
MyRow
()
{
ColumnNames =
new
List<
string
>();
Values =
new
List<
decimal
?>();
}
}
As you can see, the columns are created dynamically, because the MyRow object can hold an arbitrary number of values (so that number of columns would have to be made). The columns are generated for each String in ColumnNames and the values are bound by using the parameterized ValueConverter.
private
void
createColumns(ObservableCollection<MyRow> values)
{
while
(dataGrid.Columns.Count > 1)
dataGrid.Columns.RemoveAt(1);
dataGrid.Columns[0].Header = CommonStrings.TimeStamp;
int
columnCount = values.First().ColumnNames.Count;
for
(
int
i = 0; i < columnCount; i++)
{
GridViewDataColumn col =
new
GridViewDataColumn();
col.Header = values.First().ColumnNames[i];
col.DataType =
typeof
(MyRow);
Binding bnd =
new
Binding();
bnd.Converter =
new
MyRowCollectionConverter();
bnd.ConverterParameter = i;
col.DataMemberBinding = bnd;
dataGrid.Columns.Add(col);
}
}
However, when I try to Copy (CTRL+C), this is what I get.
TimeStamp Value1
12.12.2011. 9:51:59 MyProject.MyRow
12.12.2011. 9:52:59 MyProject.MyRow
12.12.2011. 9:53:59 MyProject.MyRow
12.12.2011. 9:54:59 MyProject.MyRow
Value1 is the name contained in the List<String> ColumnNames. That part is ok. However, I don't get the data (which are the decimal values, like 0.242524312), but instead I get the class name.
What can I do to make the copy operation retain the values in the bound property of the MyRow object instead of its class name (I guess it calls the ToString() method on whatever is inside).