Inserting a row at the top of a datatable

When I populate dropdownlists, I frequently want to add a new row at the top. I've figured out that you can easily add one at the bottom with DataTable.Rows.Add(), but that's... not elegant. This article is just a few lines of code that shows how to add one at the top.

Why bother blogging such a simple piece of code?

RAD.

I want to code quickly and efficiently and I can do that best if I have all the code samples that I needs at my fingertips instead of having to wade through endless blog entries. (some of which are innacurate)

Are you using the menus? Any subjects we can add? Tutorials

Related Articles

... and you 'll find more on the NET Development Menu

 

 

'bind a datatable to a stored procedure
Dim oDT As DataTable = DynData.SPs.FP_Trucks_SEL5(App.Database).getTable
 
'bind a telerik dropdownlist to the datasource
Me.ddlTruck.DataSource = oDT
Me.ddlTruck.ValueMember = "Truck"
Me.ddlTruck.DataMember = "Truck"
 
'create a new datarow
Dim oRow As DataRow = oDT.NewRow
'add it to the top
oDT.Rows.InsertAt(oRow, 0)
 
'set the ddl to the empty row
Me.ddlTruck.SelectedIndex = 0

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences