Raja

Raja

  • NA
  • 2k
  • 358.6k

How to remove columns after particular columns in datatable

Nov 1 2016 1:53 AM
I want to remove columns from data table after particular columns.I have used Remove method but this is delete the '("Lead Time (WEEKS)"))' columns i want to remove after the '("Lead Time (WEEKS)"))' columns.<br /> How to do it<br /><div> I have used below code.</div><div>&nbsp;</div><div>&nbsp;</div><div><pre id="pre889236" style=" 0px;">for (int i = 0; i &lt; ds.Tables.Count; i++) <br /> { <br /> for (int j = 0; j &lt; ds.Tables[i].Columns.Count; j++) <br /> { <br /> if (ds.Tables[i].Rows[7][j].ToString().Trim().Contains("Lead Time (WEEKS)")) <br /> { <br /> int y = j; <br /> if (ds.Tables[i].Rows[7][y + 1].ToString().Trim() == "" || ds.Tables[i].Rows[7][y + 1].ToString().Trim() != "") <br /> { int y1 = y + 1;<br />&nbsp;ds.Tables[i].Columns.RemoveAt(y1); <br /> } <br /> } <br /> } <br /> }</pre>&nbsp;</div>

Answers (3)