DataGridView
Is rhere anybody can explane how can I manipulate with data in datagridview
I have 4 textbox and when i press number iin text box1 must show me same data in textbox1,2,3 and in datagridview!!!
Is rhere anybody can explane how can I manipulate with data in datagridview
I have 4 textbox and when i press number iin text box1 must show me same data in textbox1,2,3 and in datagridview!!!
Sample Code:
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.textBox2.Text = this.textBox1.Text;
this.textBox3.Text = this.textBox1.Text;
this.textBox4.Text = this.textBox1.Text;
DataTable dt = new DataTable();
object[] obj=new object[1];
obj.SetValue(this.textBox1.Text,0);
//Add column and row
dt.Columns.Add(); dt.Rows.Add(obj); if (dt.Rows.Count > 0){
this.dataGridView1.DataSource = dt;}
}
How can I manipulate rows and columns.
I have one datagridview2 on form2 and when I press enter on rows they must show in datagridview1 on form1!
Vb 2005!!!!
Hi Gonza981,
Try to bind the dataGridView1 and dataGridView2 to the same data source. You may need a public class with a static DataTable in it. And the bind both datagridview to this data table.
public class Data { public static DataTable datatable = new DataTable(); static Data() {//generate initial data datatable.Columns.Add("aa"); datatable.Columns.Add("bb"); for (int i = 0; i < 50; i++) { datatable.Rows.Add("aa" + i, "bb" + i); } } }
In Form1, bind datagridview to data table using the following code:
In Form2, bind datagridview to data table using the following code:
Hope this helps.
Best regards.
Hi Gonza981,
Sorry, and here is the VB.Net code.
Public Class Data Public Shared Sharedatatable As New DataTable Shared Sub New() 'generate initial data Sharedatatable.Columns.Add("aa") Sharedatatable.Columns.Add("bb") For i As Integer = 0 To 49 Sharedatatable.Rows.Add("aa" + i.ToString(), "bb" + i.ToString()) Next i End Sub End Class
In Form1, bind datagridview to data table using the following code:
In Form2, bind datagridview to data table using the following code:
Hope this helps.
Best regards.
Dear Rong-Chun Zhang,
I also need when I press line of rows with enter in datagridview2 that line show in dtagridview1!!
Do you have code for exit from application,restart computer,shut down!!!
Hi Gonza981,
What did you mean by 'when I press line of rows with enter in datagridview2 that line show in dtagridview1'? Did you mean synch the two DataGridView? If so, try to set the two form's BindingContext to the a same object. Your Form1's code may be something like the following. Hope this helps
Public Class FormA Dim bc As BindingContext = New BindingContext() Private Sub FormA_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.DataGridView1.DataSource = Data.Sharedatatable Me.BindingContext = bc End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f As New FormB() f.Show() f.BindingContext = bc End Sub End Class
In this thread, we are mainly discussing about "DataGridView" as indicated by the posts above and the title.
Since your new question "Do you have code for exit from application,restart computer,shut down" is not directly related to the original issue, it would be best if you open up a new thread for the new question. In this way, our discussion here will not deviate too much from the original issue. This will make answer searching in the forum easier and be beneficial to other community members as well.
Thank you for your understanding.