durilai Posted October 20, 2005 Posted October 20, 2005 I am sure this has been covered, but I cannot find it. I am in the process of learning vb.net and I am working with a listview that is populated by an access table. I want to be able to pass the id of a selected item to another form in order to do another query based on that value. I am having trouble. Any help would be great. Thanks Quote
Diesel Posted October 20, 2005 Posted October 20, 2005 Save the id somewhere. Either in a list that corresponds to the order of items in the listview or wrap the data from the database in a object and use those objects to populate the listview. When a line is selected from the listview, find the object and you have the id. Is there a parent mdi form? If so, the way that I pass data from child to child is to raise an event in the child, sending the appropriate data to the parent. The parent handles the event and passes the data wherever. Im not sure if this is the recommended way (if there is one), but it's clean. namespace XtremeDotNet { #region Using Directives using System; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; #endregion #region Delegates public delegate void MyEventHandler(MyEventArgs e); #endregion public class MyForm: System.Windows.Forms.Form { public event MyEventHandler myEvent; //Constructor //Form Designer Code #region Event Handlers protected void OnMyEvent(MyEventArgs e) { if (this.myEvent != null) this.myEvent(e); } #endregion private void MyForm_SomeButtonClicked(object sender, EventArgs e) { this.OnMyEvent(new MyEventArgs("hi")); } } public class MyEventArgs: EventArgs { using System; private string text; public string Text { get { return this.text; } set { this.text = value; } } public MyEventArgs(string text) { this.text = text; } } } something like that Quote
durilai Posted October 20, 2005 Author Posted October 20, 2005 Thanks for the help, but I am not using C# i am using vb.net. I am not sure of the differences, but for some more detailed info I am doing this as a project and to learn so I am not to up to speed on vb.net. My list view has three columns id, desc, date. All I need is the id, which I cannot see on the form since I made the column size 0. They are only allowed to select one item and I want to pass the id of the selected item to the other form. I am lost, please help. Thanks Quote
Diesel Posted October 20, 2005 Posted October 20, 2005 If you are doing this to learn, why not read a book. Quote
durilai Posted October 20, 2005 Author Posted October 20, 2005 I have ordered a book, but I learn best by trying. I feel that these problems are minor, and I have searched but not having any luck. Quote
durilai Posted October 20, 2005 Author Posted October 20, 2005 Is the listview a good way of doing this or should I be using a datagrid or something else? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.