0
I have a class that has two methods that receive what is typed in textBox
, all this stored in one dataTable
(without database). When I click on a line (Row
) of dataGridView
I show the values saved in dataTable
back in the textBox
and so I can change the value of textBox
, but not save in dataTable
because I don’t know how to add this change.
If anyone can help me I’d really 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();
}>
See if I can help you... I don’t know if your problem is to set the value to the Datatable Datarow or if it is to take the Rowindex value.
– Carlos H