Solved

Manually Add Row at start of Datatable

Posted on 2011-02-21
4
469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 500 total points
ID: 34947644
0
 
LVL 6

Expert Comment

by:AkAlan
ID: 34947715
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
ID: 34947883
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
ID: 34947896
rawinnlnx9 that link did exactly what I needed it to.. Thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 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