Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear Sir/Mam
My Name hiren.
1. I have Use Like One dataGridView and More Than Ten button View to Different SQL Query.

2.My Purpose
This dataGridView open One Form by Click Common button and All data Write to Second Form Data Grid View.

Please describe me.
I have more than 3 days Search for This topic i confused.

What I have tried:

I have search internet but select row transfer ya any particular value transfer
not show all value.please help me.
Posted
Updated 30-Nov-17 2:46am
Comments
Sinisa Hajnal 30-Nov-17 6:26am    
Change the perspective, don't think how to change the grids, instead change data sources (copy DataTable or fill another DataSet, collection, whatever you use).
You didn't show any code, not even filling the first grid, it is hard to help like this.
________________ 30-Nov-17 8:36am    
If you are using WinForm, you can override the constructor of new form like:
public

public partial class Form2 : Form
{
public Form2(DataGridView dataToShow)
{
InitializeComponent();
this.Controls.Add(dataToShow);

}
}

Than you can see somthing fanny with adding following code on button click in Form1:

private void button1_Click(object sender, EventArgs e)
{
Form2 fwWithSameDgvClone = new Form2(this.dataGridView1);
fwWithSameDgvClone.Show();
}


This mean, WinForm controls has own limitations to use on different forms.

But same way you can pass the data to Form2 and bind this data to other DataGridView , existing on Form2.

1 solution

First form - DataGridView and button:

public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();

			this.dataGridView1.DataSource = new List<string> { "qwewqe", "qweqweqwe", "aaaaaaa" };
		}

		private void button1_Click(object sender, EventArgs e)
		{			
			Form2 fwWithSameDgvClone = new Form2(this.dataGridView1.DataSource);
			fwWithSameDgvClone.Show();
		}
	}




Second form - only DataGridView:

public partial class Form2 : Form
	{
		
		public Form2(object dataToShow)
		{
			InitializeComponent();
			dataGridView1.DataSource = dataToShow;
		}
	}



Pay attention - dataGridView1 in Form2 created in form designer, and it is different object (designer uses "new" operator!), not same with Form1 dataGridView1.
 
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