Passing value

durilai

Newcomer
Joined
Oct 20, 2005
Messages
10
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
 
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.

C#:
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
 
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
 
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.
 
Back
Top