si certo ti posto una funzione che spero possa esserti utile.
private DataTable getNewTable(DataTable source, string filter)
{
if (source==null || filter==null || filter.Trim()=="")
throw new ArgumentException();
if (source.Columns.Count!=filter.Length)
throw new ArgumentException();
try
{
DataTable dt = new DataTable();
//creo la struttura dati
List<string> colonne = new List<string>();
for (int i = 0; i < filter.Length; i++)
if (filter[i] == Convert.ToChar("1"))
{
dt.Columns.Add(new DataColumn(source.Columns[i].ColumnName));
colonne.Add(source.Columns[i].ColumnName);
}
dt.AcceptChanges();
//sincronizzo i dati
foreach (DataRow dr in source.Rows)
{
DataRow newRow = dt.NewRow();
foreach (string nomeColonna in colonne)
newRow[nomeColonna] = dr[nomeColonna];
dt.Rows.Add(newRow);
}
dt.AcceptChanges();
return (dt.Rows.Count == 0 || dt.Columns.Count == 0) ? null : dt;
}
catch { return null; }
}
Nelle direttive using usa System.Collections e System.Data. Un esempio di chiamata alla funzione potrebbe essere:
DataTable nuovoDataTable = getNewTable(vecchioDataSource, "10110111");
Non ho avuto modo di testarla ma dovrebbe funzionare bene, se hai problemi chiedi pure.