So i have a datagridview which is populated with a list of objects. I added on the form 3 textboxes and a button. The question is how to insert and populate another row into the datagridview with the text from textboxes.
this is my class:
class Professor
{
private int id;
private string name;
private double salary;
public Professor()
{
this.id= 0;
this.name = null;
this.salary= 0;
}
public Professor(int m, string n, double s)
{
this.id= m;
this.name = n;
this.salary= s;
}
}
This is the declaration for the list:
ArrayList listProfessors = new ArrayList();
This is the button which populates the DataGridView:
private void addInGridViewFromList_Click(object sender, EventArgs e)
{
string linie;
System.IO.StreamReader file= new System.IO.StreamReader("D:\\Profesor\\Profesor\\Profesori.txt");
while ((line= file.ReadLine()) != null)
{
string[] t = line.Split(',');
listProfessors .Add(new Professor(Convert.ToInt32(t[0]), t[1], Convert.ToDouble(t[2])));
}
file.Close();
dataGridView1.DataSource = listProfessors ;
}
And here on this button i want to add another row manually(using texboxes) into the DataGridView.
private void AddFromKeyboard_Click(object sender, EventArgs e)
{
}