?
Solved

how to read from a dataset datatable and add 3rd  row into listbox

Posted on 2007-08-07
3
Medium Priority
?
959 Views
Last Modified: 2013-12-17
i got 2 datasets i wan to read data from the 2 nd table of datset and diplay the 3 rd colum values into the list box  when i press insert button can any one help me
and also remove button
when i click a particular one and prese remove that should be removed and when i select all all should be reoved can any help me with this please
0
Comment
Question by:kranthi4uonly
3 Comments
 
LVL 8

Expert Comment

by:sabeesh
ID: 19648235
DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();
        ListBox lst = new ListBox();
        foreach(DataRow row in ds1.Tables[1].Rows)
        {
            lst.Items.Add(row[2].ToString());
        }
0
 
LVL 5

Expert Comment

by:ursangel
ID: 19651787
To remove a selected row
DataRow selectedRow = dataTable.Rows[listBox1.SelectedIndex];


selectedRow.Delete();
0
 
LVL 2

Accepted Solution

by:
patilmmilind earned 1000 total points
ID: 19653414
To Load Table Values from Dataset use following code
(It is just an Example Code, Modify it as per your requirement)

private void LoadList()
{
    // Get the table from the data set
    DataTable dtable = _DataSet.Tables["Titles"];

    // Clear the ListView control
    listView1.Items.Clear();

    // Display items in the ListView control
    for (int i = 0; i < dtable.Rows.Count; i++)
    {
        DataRow drow = dtable.Rows[i];

        // Only row that have not been deleted
        if (drow.RowState != DataRowState.Deleted)
        {
            // Define the list items
            ListViewItem lvi = new ListViewItem(drow["title"].ToString());
            lvi.SubItems.Add (drow["title_id"].ToString());
            lvi.SubItems.Add (drow["price"].ToString());
            lvi.SubItems.Add (drow["pubdate"].ToString());

            // Add the list items to the ListView
            listView1.Items.Add(lvi);
        }
    }
}

Now, to remove Row From DataTable:

You will get the Index of the row from Listview which you want to delete . You can use this Index to delete actual row from DataTable. The code is as follows

dataTable.remove(dataTable.getItem(INDEX_FROM_LISTVIEW));

Wish you best luck
(NOTE: Never use numerical values in your code, always use names or define constant values)

Regards,
Milind
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 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