J
Joe
I'm looking for a suggestion on how to do the following:
We have a case when values returned by DataTable.Rows[r][c] should be
different than what is actually stored.
For example:
DataTable dt = new DataTable();
dt.Columns.Add("Column1");
dt.Rows.Add(new object[] {"Test Value") );
When reading the code I would like to do a lookup and see if there is a
replacement value for "Test Value" and if so return that. The replacement
value would be stored in another table or anywhere that makes sense.
Ideally it would be nice to create my own DataRow and override the Item
property so I can use my DataTable in say a DataGridView and also get the
replacement value instead of the stored value if one existed.
I would like to do the following (but of course I can't because Item is not
overloadable in the DataRow):
public class MyDataRow : DataRow
{
private object replacementValue = "Some other value";
...
public object this[int index]
{
get
{
if (replacementvalue != null)
return replacementvalue;
return base[index];
}
}
}
So in a DataGridView or any other object that was reading dt.Rows[r][c]
would get "Some other value" instead of "Test Value"
Is there anyway to return a different value for the DataRow? Maybe there is
an event I don't know about that would allow me to do this.
Thanks for any help,
Joe
We have a case when values returned by DataTable.Rows[r][c] should be
different than what is actually stored.
For example:
DataTable dt = new DataTable();
dt.Columns.Add("Column1");
dt.Rows.Add(new object[] {"Test Value") );
When reading the code I would like to do a lookup and see if there is a
replacement value for "Test Value" and if so return that. The replacement
value would be stored in another table or anywhere that makes sense.
Ideally it would be nice to create my own DataRow and override the Item
property so I can use my DataTable in say a DataGridView and also get the
replacement value instead of the stored value if one existed.
I would like to do the following (but of course I can't because Item is not
overloadable in the DataRow):
public class MyDataRow : DataRow
{
private object replacementValue = "Some other value";
...
public object this[int index]
{
get
{
if (replacementvalue != null)
return replacementvalue;
return base[index];
}
}
}
So in a DataGridView or any other object that was reading dt.Rows[r][c]
would get "Some other value" instead of "Test Value"
Is there anyway to return a different value for the DataRow? Maybe there is
an event I don't know about that would allow me to do this.
Thanks for any help,
Joe