4
Answers

How to pass the DataGridView object to other DataGridView object?


I have to forms, in the first form appers the data grid where I put the data inside. Then in that form I press a boton, and a second form appers with a DataGridView with the same info that I wrote on the first form.
I pass a DataGridview object on the second form constructor but, the info from the first gridview is not showing.
Form 1 source code
public
partial class Form1 : Form
{
   public Form1()
   {
      InitializeComponent();
   }
   private void button1_Click(object sender, EventArgs e)
   {
      new Form2(dataGridView1).Show();
   }
}
Form 2 source code
public
partial class Form2 : Form
{
   public Form2()
   {
   InitializeComponent();
   }
   public Form2(DataGridView dataGridView)
   {
   InitializeComponent();
   this.dataGridView1.DataSource = dataGridView.DataSource; //Not working
   this.dataGridView1 = dataGridView; //Not Working
   }

}
Answers (4)
1
Amit Gupta

Amit Gupta

NA 16.5k 25.6k 8y
If the database column is type of string then it recommend you to change the datatype to decimal, it will help you in future and many more queries.
 
However, if currency contains ,(comma) and you need to validate that by using the replace method
 
String cur ="12,000";
var value = Convert.ToDecimal (curr.Replace (",", "");
 
// now value contains only numbers without and seperator