I have the following parameterization of my datagridview:
List<ModelAluno> alunos;
ModelAluno aluno = new ModelAluno();
public PesquisaAluno(List<ModelAluno> alunos)
{
InitializeComponent();
this.alunos = alunos;
}
private void PesquisaAluno_Load(object sender, EventArgs e)
{
ConfiguraDataGrid();
foreach (var aluno in alunos)
{
dg.Rows.Add(aluno.Nome, aluno.Cpf, aluno.Matricula.IdCurso);
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void ConfiguraDataGrid()
{
dg.Columns.Add("dg_Nome", "Nome");
dg.Columns.Add("dg_Cpf", "CPF");
dg.Columns.Add("dg_Curso", "Curso");
dg.ReadOnly = true;
dg.AllowUserToAddRows = false;
foreach (DataGridViewColumn column in dg.Columns)
{
if (column.DataPropertyName == "Nome")
column.Width = 300; //tamanho fixo da primeira coluna
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
In the case, I'm getting a list of students from another form and I present in my datagridview only the fields I want (name, cpf and idcurso).
In the CellContentClick method I need to return the selected student to my previous form, but I can not return only those three fields, I need to return the mounted object (which is retrieved initially in a search in SQL Server and is already stored in the list received in the datagridview)How do I return the entire object? Also, how do I, when pressing enter, I select the object that I want and present in the textbox of the previous form?