?
Solved

adding data for selected row in datagrid to listbox

Posted on 2005-04-27
4
Medium Priority
?
1,790 Views
Last Modified: 2010-08-05
First of all i don't want to just bind the column in dataset to listbox and have it display all the data, i just want it to display list of items that in a column for a selected row(and it can have multiple rows under same id) appear. So table looks like:

id  Note
1   firstnote
2   second note
2   third note
2   4th note
3   5th note
....

so if a user selects a row with id =2 in datagid, then listbox should add Nots related to all the rows that have that selected it. In this case it should add those 3 notes if any of the id=2 is selected.

If i just bind listbox to datasource, set valuemember and display member, they just dump entire table's notes in that listbox. How can i make it so it will only do as i described above?
0
Comment
Question by:MellowD0c
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
jaynus earned 200 total points
ID: 13887845
foreach(DataRow row in MyDataSet.Tables[0].Rows) {
     if(row.ItemArray[0] == MySelectedIdNumber) {                  // Check if the ID and the selected ID match
           MyListBox.Items.Add(row.ItemArray[1].ToString());      // Add notes to the list
     }
}
0
 

Author Comment

by:MellowD0c
ID: 13888246
private void dgBugTracker_SelectedCellChanged(object sender, System.EventArgs e)
            {

                  foreach(DataRow row in myDS2.Tables[0].Rows)
                  {
                        if(Convert.ToString(row.ItemArray[0]) == Convert.ToString(txtIssue.Text))
                        {   // Check if the ID and the selected ID match
                              lstNoteH.Items.Clear();
                              lstNoteH.Items.Add(row.ItemArray[41].ToString());      // Add notes to the list
                        }
                  }            
            }

Ok. What the above does is that if i select any row from datagrid it adds data for that selected row from required column, but its still not doing what i wanted. Actually right now its doing as if i would bind that row to some text box and have text box display value for that row with the exception that it doesn't get updated on selecting a different row with same id cause ostensibly i have check to match for id and since id doesn't change, therefore, it doesn't update the listbox either. Since everything else but that particular column value is different between same id's, is there any way else i could have it make a check for row change and add that particular column value from all rows of same id to the list box? Right now it just adds item of selected row to listbox and values from other exact same id's.

So back to my original example:

id  Note
1   firstnote
2   second note
2   third note
2   4th note
3   5th note
....

 It is adding only that id value that i select first of the 3, but i want to select id 2 and have it dump all the related notes from other two id's as well. So if i select id 2, i should have the following in listbox:

second note
----
third note
----
4th note
---

But as the code is right now, it only adds which ever "2" id i select first and doesn't change or add on selecting other same ids'.
0
 

Author Comment

by:MellowD0c
ID: 13888606
jaynus, it worked just had to place items.clear method elsewhere and i am all set. Thanks a bunch!
0
 
LVL 4

Expert Comment

by:jaynus
ID: 13888662
Oops!!! Yah sorry I forgot to mention to clear it every change, my bad!! Apologies for that, Mellowdoc. Glad it works!

-jaynus
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

839 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