Click here to Skip to main content
15,881,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Quote:
I want to remove a column from datatable

the column is a part of expression I want to remove it once the expression is calculated.
 μ  LSL USL are columns already present

Lower.Expression = "(Convert(μ,'System.Double')-Convert(LSL,'System.Double'))/(3.0*sigma)";
Upper.Expression = "(Convert(USL,'System.Double')-Convert(μ,'System.Double'))/(3.0*sigma)";
CpK.Expression = "IIF(Lower < Upper, Lower, Upper)";



table1.Columns.Remove("Lower");//Exception
   
table1.Columns.Remove("Upper");//Exception



I want to remove lower and upper once the data is populated
Posted
Updated 20-Mar-14 2:48am
v3
Comments
BELGIUMsky 20-Mar-14 6:16am    
I don't have experience with that problem but.
Can't you just hide the columns?

Why do you want to remove them?
VICK 20-Mar-14 8:27am    

table1.Columns.Remove("Lower");

table1.Columns.Remove("Upper");



These seems to be fine. and should be working. Can you tell that what error or exception you are getting on that?
FarhanShariff 20-Mar-14 8:39am    
first of all, you can't remove columns from a DataTable if they are involved in an Expression property. If you try to do so, you'll get an exception.

Secondly, you can't hide columns in a DataTable because the DataColumn class doesn't have a Visible property - hence the exception .
VICK 20-Mar-14 8:44am    
Well, I was not aware of the first part. So Thanks for sharing this knowledge with me. Would be searching on GOOGLE for enhancement in that.
while for the Second, I am pretty sure and have it in knowledge, that's y didnt advise you that.

ANY WAY as you quoted that Columns can't be removed from a Datatable if they are involved in an Expression. Than Why are you trying that??/ :(
FarhanShariff 20-Mar-14 8:46am    
I want to remove them once I have calculated and CpK column is populated

1 solution

Instead Of Remove, Why Not Visible = false
 
Share this answer
 
Comments
FarhanShariff 20-Mar-14 6:22am    
I tried to hide it
table1.Columns["Lower"].Visible = false;
It say you are missing directive or an assemble reference ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900