cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete Empty Collection Columns

Anonymous
Not applicable
Hi guys,

Just a quick one. I have a collection with many empty columns at the end and i would like to delete them all.
Is there a possibility to do that? They are somehow dynamical displayed, sometimes there are data, and sometimes they don't have.
How can I do that?

Thank you,
Ionut Cohen

------------------------------
Ionut Cohen
RPA Developer
Luxoft Romania
Europe\Bucharest
------------------------------
1 REPLY 1

AmiBarrett
Level 12

Here's a C# stage I wrote. 

Edit: I apologize ahead of time for the inefficiency of this one, especially if there's a ton of columns. I'm keen to see if anyone has a better solution!

Inputs:
Collection - Collection

Outputs:
New Collection - Collection

DataView dv = Collection.DefaultView;
//Label to prevent 'Collection was modified' errors	
Out:
foreach(DataColumn col in Collection.Columns)
{
	if(col.DataType == System.Type.GetType("System.String"))
		dv.RowFilter = col.Caption+" =''";
	else
		dv.RowFilter = col.Caption.ToString() + " = null";
	if(dv.Count == Collection.Rows.Count)
	{
		Collection.Columns.Remove(col);
		goto Out;
	}
}
New_Collection = Collection;



------------------------------
Ami Barrett
Lead RPA Software Developer
Solai & Cameron
America/Chicago
------------------------------