Solved

Manually Add Row at start of Datatable

Posted on 2011-02-21
4
463 Views
Last Modified: 2012-06-27
I have a combobox on a form that I am filling by setting the Datasource Property. I want to be able to add a row to the start of the Datatable to display at the top of the combobox that has a 0 Value but instructs the user to select an Option ie: Select Customer....

I have managed to add a row to the datatable, but I don't know how to index it as the first row.

Thanks
Dim sCustomers As String = "SELECT * FROM tCustomers"
        Dim daCustomers As New SqlClient.SqlDataAdapter(sCustomers, myConn.sqlConn)
        daCustomers.Fill(dsCustomers, "dtCustomers")

        Dim newCustomersRow As DataRow = dsCustomers.Tables("dtCustomers").NewRow()
        newCustomersRow("ID") = "0"
        newCustomersRow("sName") = "Select Customer...."
        dsCustomers.Tables("dtCustomers").Rows.Add(newCustomersRow)

        cboCustomerName.DataSource = dsCustomers.Tables("dtCustomers")
        cboCustomerName.DisplayMember = "sName"
        cboCustomerName.ValueMember = "ID"

Open in new window

0
Comment
Question by:mgordon-spi
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 500 total points
Comment Utility
0
 
LVL 6

Expert Comment

by:AkAlan
Comment Utility
Here is an example of how I do what you are asking. It is a function of the DropDownList more than doing it with your dataset. the AppendDataBoundItems is the important option to remember.

<asp:DropDownList ID="ddlSite" runat="server" Width="145px"  AppendDataBoundItems="true"  DataSourceID="sdsSite"
        DataTextField="SiteName" DataValueField="SiteID">
        <asp:ListItem Value="0">--Site--</asp:ListItem>
    </asp:DropDownList>
0
 

Author Comment

by:mgordon-spi
Comment Utility
This is a vb form not a webpage. I can append quite easily in asp.net, but I am at a loss of how to do it with an Application
0
 

Author Comment

by:mgordon-spi
Comment Utility
rawinnlnx9 that link did exactly what I needed it to.. Thank you
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to close and re-open a stream reader object 5 24
Object to array 7 26
Vb.Net Menu 1 20
Set form below another form 3 24
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now