Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Datatable Adding Row

Datatable Adding Row

Scheduled Pinned Locked Moved C#
databasehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SJR_1
    wrote on last edited by
    #1

    I'm returning a datatable from the DB, I need to add a row to that datatable for display only. That piece is working fine, the issue is I need that record to be the first record displayed in the cbo box. System.Data.DataRow dr = WorkTable.NewRow(); WorkTable.Rows.Add(new object[] {"ALL", "AL","","","","","","",-2,1,"UNKNOWN"}); cbo.DataSource = WorkTable; --I need to have the added line first in the combo box. Thanks

    V 1 Reply Last reply
    0
    • S SJR_1

      I'm returning a datatable from the DB, I need to add a row to that datatable for display only. That piece is working fine, the issue is I need that record to be the first record displayed in the cbo box. System.Data.DataRow dr = WorkTable.NewRow(); WorkTable.Rows.Add(new object[] {"ALL", "AL","","","","","","",-2,1,"UNKNOWN"}); cbo.DataSource = WorkTable; --I need to have the added line first in the combo box. Thanks

      V Offline
      V Offline
      vineas
      wrote on last edited by
      #2

      Instead of setting the data source of the combobox to the table, set it to a sorted view. Then all you need to do is make sure that the view is sorted so that your new row is first ... perhaps by adding a new column to the table that is null for everything other than your new row. I tried this quickly, and seems to work OK, but it looks like the sort put's null values ahead of non-nulls, so you'll need to do a descending sort. ----- In the land of the blind, the one eyed man is king.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups