Click here to Skip to main content
15,905,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear all ,

i have small table student(id,name,last_name,address) and small screeen with datagridview iam trying to make insert and update
i want to add record in datagrid and then user enter data in that record
this my code , i do not know if it's possible or not
C#
private void button1_Click(object sender, EventArgs e)
      {


              DataRow dr = dt.NewRow();
              dr["student_id"] = Convert.ToInt32(textBox1.Text);
              dr["student_name"] = textBox2.Text;
              dr["student_last_name"] = textBox3.Text;
              dr["address"] = textBox4.Text;
              dt.Rows.Add(dr);
              obj.addstudent(Convert.ToInt32(dr["student_id"].ToString()), dr["student_name"].ToString(), dr["student_last_name"].ToString(), dr["address"].ToString());
              dataGridView1.DataSource = dt;
      }


other thing update i want event firing after all cells in the same row updated not firing the event for each cell separetly like what happen in asp (rowupdating) this is my code :

C#
int x, y;
       private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
       {
           x = dataGridView1.CurrentCellAddress.X;
           y = dataGridView1.CurrentCellAddress.Y;

       }

       private void dataGridView1_CancelRowEdit(object sender, QuestionEventArgs e)
       {
           x = -1;
           y = -1;
       }
       int id;
       string name, lname, add;
       private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
       {
           string s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
           id=Convert.ToInt32( dataGridView1 .Rows[e.RowIndex ].Cells[0].Value.ToString());
           name=dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
           lname = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
           add = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();



       }

       private void btnupdate_Click(object sender, EventArgs e)
       {

           int done = obj.updat(id,name,lname,add);

       }


thanks and regards
Posted

1 solution

Please try this link[].
It has the CRUD functionality in GridView.hope it will help you :)
 
Share this answer
 
Comments
fady_hasnaa 19-May-14 6:18am    
no sir,
this link for gridview in asp iam talking about datagrid in c#

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