Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, July 8, 2015 5:27 PM
I am writing a program that collects data using a table adapter. I want to filter the data more, so I create an empty table using CLONE(). I scan the table, apply the filter, and create a new row in the cloned data table. However, when I try to assign the value to the column, I get an error that the column is read only.
Is there an easy way to remove the "read only" from the cloned data table columns?
I am including some code to -- hopefully -- provide greater clarity. Thanks for any help.
public void Process()
{
TableAdapters.WSTableAdapter T1 = new TableAdapters.WSTableAdapter();
DataTable DT = T1.GetData(Period1, Period2);
DataTable DV = DT.Clone();
int N = DT.Rows.Count; int I; int ET;
for (I = 0; I < N; I++)
{
DataRow DR = DT.Rows[I];
ET = (int)DR["Type"];
if(CorrectType(ET))
{
DataRow R1 = DV.Rows.Add();
R1["field1"] = DV["field1"];
R1["field2"] = DV["field2"];
R1["field3"] = DV["field3"];
}
}
DataView V1 = new DataView(DV);
V1.Sort = SortValue;
PrintReport(V1);
}
private bool CorrectType(int ET)
{
switch (ET)
{
case 1: if (tReport.Value1 == 1) { return true; } else { return false; }
case 2: if (tReport.Value2 == 1) { return true; } else { return false; }
case 3: if (tReport.Value3 == 1) { return true; } else { return false; }
case 4: if (tReport.Value4 == 1) { return true; } else { return false; }
case 5: if (tReport.Value5 == 1) { return true; } else { return false; }
case 6: if (tReport.Value6 == 1) { return true; } else { return false; }
default: return false;
}
}
All replies (2)
Wednesday, July 8, 2015 6:13 PM âś…Answered
You can change the ReadOnly property on the associated data column. If the column is a computed column though it isn't going to work. Ideally you should simply set the column value when you create the row rather than setting it after the fact. You can do that by passing the values as part of the Add call. Alternatively you might be able to create the row using NewRow off the table and then set the columns normally before adding the row to the table. I've never tried that approach but it probably will work.
Michael Taylor
http://blogs.msmvps.com/p3net
Friday, July 10, 2015 1:44 PM
Doing the Add as follows worked:
DV.Rows.Add(DV["field1"], DV["field2"], DV["field3"] );
Thanks