locked
Add new row to DataTable RRS feed

  • Question

  • User944339287 posted

    Dear all,

    Below is my code to show returned result to ListView

    I wondering how can i add a specific row on top of DT.DefaultView?

    Dim DT as new DataTable
    Dim report as new DBreport
    
    DT = report.return_report("All")
    Me.lvReport.DataSource = DT.DefaultView
    Me.lvReport.DataBind()



    Tuesday, October 23, 2018 10:28 AM

All replies

  • User475983607 posted
    Add a sort column and sort by that column to fix order.
    Tuesday, October 23, 2018 10:46 AM
  • User753101303 posted

    Hi,

    This is done using https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.rows?redirectedfrom=MSDN&view=netframework-4.7.2#System_Data_DataTable_Rows

    (you can also use InsertAt and tell where to insert the row, AFAIK the DefaultView uses this "physical order" by default).

    Tuesday, October 23, 2018 10:51 AM
  • User839733648 posted

    Hi kengkit,

    According to your description and code, I could not fully understand your requirement.

    I wondering how can i add a specific row on top of DT.DefaultView?

    The fomat of listview is special. What is your listview displaying now? What format of the row you want to add to your listview?

    Besides,I suggest that maybe you could add LayoutTemplate to your listview to show the row.

    Best Regards,

    Jenifer

    Wednesday, October 24, 2018 9:29 AM
  • User61956409 posted

    Hi kengkit,

    Add new row to DataTable

    You can refer to the following code snippet to insert a new row at the specified location.

    Dim DT As DataTable = New DataTable()
    
    DT.Columns.Add("Field1")
    DT.Columns.Add("Field2")
    
    DT.Rows.Add("row11", "row12")
    DT.Rows.Add("row21", "row22")
    
    'create a new row
    Dim DR As DataRow = DT.NewRow()
    DR("Field1") = "row00"
    DR("Field2") = "row01"
    
    'insert a new row at the specified location DT.Rows.InsertAt(DR, 0)

    With Regards,

    Fei Han

    Thursday, November 1, 2018 7:08 AM