Home > DeveloperSection > Forums > How to display data results in DatagridView in another Form?
Pravesh Singh

Total Post:411

Posted on    October-20-2014 12:38 AM

 C# C# 

 1 Reply(s)
 1190  View(s)
Rate this:
I'm having a tough time trying to display my data information in another form which has a DataGridView, if a button is clicked
To display the results in the same Form in dgv isn't a problem but to display it in Form 2 in a dgv is giving me a headache (:
cmd.commandText: SELECT * FROM tblproducts
void btnDisplay_Click(object sender, EventArgs e)
if (comboBox1.SelectedValue.ToString() != null && comboBox2.SelectedValue.ToString() != null)
open connection
new Form2().ShowDialog();
?????? what next??
dataGridView1.DataSource = get Info from Form1;

Ankita Pandey
Ankita Pandey

Total Post:183

Posted on    October-20-2014 12:39 AM

Why don't you add a static class to your project, populate this in Form1 then add a property to the static class holding your list of objects, then bind this to your datagridview in Form2??

open connection
new Form2().ShowDialog();
Form2.Passvalue = dataGridView1.DataSource;

public partial class DataGridView : Form2
private string Data;
public string Passvalue
get { return Data; }
set { Data = value; }
public DataGridView()
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
dataGridView1.DataSource = Data;

Don't want to miss updates? Please click the below button!

Follow MindStick