Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am haivng two forms
in my project in form2 created listbox item,when i click the button the selected listbox items go to form1 in data grid view column
how can i do?
Posted

you can use delegate and custom event for this purpose.
 
Share this answer
 
On click of button u should store selected list box value in session and in second page u should check session then bind value in grid .
 
Share this answer
 
In the form you want the data to go to, create another constructor there that takes a parameter. For example the name of the second form in Form2 and inside the 1st form, let's say Form1, you have a button click event where you choose a value and when you a button the other form shows.

C#
//Inside the 1st form - Form1
public void Button1_Click(Object sender, EventArgs e)
{
    string value = DropDownList.SelectedValue;
    Form2 f = new Form2(value);
    f.Show();
}



In the Form2 class you must need a custom constructor to accept this value, so lets create that. Also, you need probably a global variable or a property so that value is known throughout the class. Let's use a global variable in this example to keep it simple.

C#
//Global variable
public readonly string _value; //remove readonly if you want to change the variable value.

public Form2(string value)
{
    _value = value;
}


Then use the _value however you need to include it in your datagridview.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900