Move datatable and filter datatable based on conditions

Source: Internet
Author: User

/// <Summary> <br/> // move the able in the starting position and moving direction, and return a new datatable <br/> /// </Summary> <br/> /// <Param name = "DT"> datatable to be moved </param> <br/> /// <Param name = "startrow"> move (Index starts from 1) </param> <br/> /// <Param name = "movecount"> Number of rows to be moved </param> <br/> /// <Param name = "moveup "> whether to move up (true indicates move up; false indicates move down) </param> <br/> /// <returns> after the data is moved, if the movement is incorrect, the original table is returned. </returns> <br/> Public datatable getnewtable (datatable DT, int startrow, int movecount, bool moveup) <br/>{< br/> # region moves the able in the starting position and moving direction, and returns a new datatable </P> <p> datarow DR = DT. newrow (); <br/> dr. itemarray = DT. rows [startrow-1]. itemarray; <br/> int rowcount = DT. rows. count; <br/> If (startrow> rowcount) // move the row outside the row number <br/> return DT; <br/> If (moveup) // move up <br/>{< br/> If (startrow-movecount <= 0) {}< br/> else <br/> {<br/> for (INT I = 0; I <movecount; I ++) <br/> DT. rows [startrow-I-1]. itemarray = DT. rows [startrow-I-2]. itemarray; <br/> DT. rows [startrow-movecount-1]. itemarray = dr. itemarray; <br/>}< br/> else // move down <br/>{< br/> If (startrow + movecount> rowcount) {}< br/> else <br/> {<br/> for (INT I = 0; I <movecount; I ++) <br/> DT. rows [startrow + I-1]. itemarray = DT. rows [startrow + I]. itemarray; <br/> DT. rows [startrow + movecount-1]. itemarray = dr. itemarray; <br/>}< br/> return DT; <br/># endregion <br/>}

This is the method for moving the datatable.

 

/// <Summary> <br/> // filter the table based on the conditions <br/> /// </Summary> <br/> /// <Param name =" DT "> tables before filtering </param> <br/> // <Param name =" filter "> filter condition </param> <br/> /// <returns> return the filtered table </returns> <br/> Public datatable getnewtable (datatable DT, string filter) <br/>{< br/> # region filter tables based on conditions <br/> datatable newtable = DT. clone (); <br/> datarow [] DRS = DT. select (filter); <br/> foreach (datarow DR in DRS) <br/>{< br/> object [] arr = dr. itemarray; <br/> datarow newrow = newtable. newrow (); <br/> for (INT I = 0; I <arr. length; I ++) <br/> newrow [I] = arr [I]; <br/> newtable. rows. add (newrow); <br/>}< br/> return newtable; <br/># endregion <br/>}

filter data based on ble and query conditions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.