I have a class that has two methods that get what is typed in textBox
, all stored in dataTable
(without database). When I click on a line ( Row
) of dataGridView
I show the values saved in dataTable
back in textBox
so I can change the value of textBox
, but do not save dataTable
since it does not I know how to add this change.
If someone can help me, I would appreciate it.
<public class Dados
{
private string _nome;
private string _email;
public Dados(string nome, string email)
{
this._nome = nome;
this._email = email;
}
public string Nome
{
get{return _nome;}
set{_nome = value;}
}
public string Endereco
{
get{return _email;}
set{_email = value;}
}
public string AlterarNome
{
get{return _email;}
set{_email = value;}
}
public string AlterarEndereco
{
get{return _email;}
set{_email = value;}
}
}>
// Part of Form1.cs
public Form1()
{
InitializeComponent();
dt.Columns.Add("Nome", Type.GetType("System.String"));
dt.Columns.Add("Email", Type.GetType("System.String"));
dataGridView1.DataSource = dt;
}
//salvar o que foi digitado
private void bt_salvar_Click_1(object sender, EventArgs e)
{
Pessoa dados = new Pessoa(txt_nome.Text, txt_email.Text);
DataRow dr = dt.NewRow();
dr["Nome"] = dados.Nome;
dr["Email"] = dados.Email;
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
}
//botão para editar
private void alterarToolStripMenu_Click_1(object sender, EventArgs e)
{
//espera
dataGridView1.Update();
dataGridView1.Refresh();
}
//botão excluir row/cliente
private void excluirToolStripMenu_Click_1(object sender, EventArgs e)
{
int indexDaLinhaSelecionada = dataGridView1.CurrentCell.RowIndex;
dataGridView1.Rows.RemoveAt(indexDaLinhaSelecionada);
dataGridView1.Update();
dataGridView1.Refresh();
}>