You can filter data in grid via using
DataTable.Select() method[
^], which returns an array of DataRow objects.
DataTable srcdt = (DataDatable)grid.DataSource;
DataTable dstdt = new DataTable();
dstdt.Columns.Add(new DataColumn("NPM", typeof(int)));
for(int i=0; i<srcdt.Rows.Count;i++)
{
var processedNPM = srcdt.Rows[i][0];
var npmcheck = dstdt.Select(string.Format("NPM={0}", processedNPM)).FirstOrDefault();
if(npmcheck!=null)
{
}
else
{
dstdt.Rows.Add(srcdt.Rows[i].Clone());
}
}
Another way is to use Linq:
dstdt = srcdt.AsEnumerable()
.GroupBy(x=>x.Field<int>("NPM"))
.Select(grp=>dstdt.LoadDataRow(new object[]{grp.Key}, false))
.CopyToDataTable();
Note: change
x.Field<int>("NPM")
to your data type, for example:
x.Field<string>("NPM")
- if a
NMP
field is type of string.
Good luck!