2
I am trying to set the data of the selected Datagrid line, which comes from B.D., to show in each Textbox. The data of each column of the selected row goes to a Textbox. How do I? Which method to use?
namespace EstoquePeca
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
txtPeca.Focus();
}
//Consultar Todos
private void Button_Click_2(object sender, RoutedEventArgs e)
{
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/estoque.mdb");
OleDbCommand aCommand = new OleDbCommand("select * from ESTOQUEPECA", aConnection);
aConnection.Open();
var Consulta = aCommand.ExecuteReader();
GridDados.ItemsSource = Consulta;
GridDados.Columns[0].Header = "Código";
GridDados.Columns[1].Header = "Quantidade";
GridDados.Columns[2].Header = "Descrição";
GridDados.Columns[3].Header = "Alternativo 1";
GridDados.Columns[4].Header = "Alternativo 2";
}
//Consultar pelo código
private void Button_Click_1(object sender, RoutedEventArgs e)
{
string sql = "select * from ESTOQUEPECA WHERE COD ='" + txtPeca.Text + "'";
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/estoque.mdb");
OleDbCommand aCommand = new OleDbCommand(sql, aConnection);
aConnection.Open();
var Consulta = aCommand.ExecuteReader();
try
{
if (txtPeca.Text.Equals(""))
{
MessageBox.Show("Digite o código da Peça!");
}
else
{
GridDados.ItemsSource = Consulta;
GridDados.Columns[0].Header = "Código";
GridDados.Columns[1].Header = "Quantidade";
GridDados.Columns[2].Header = "Descrição";
GridDados.Columns[3].Header = "Alternativo 1";
GridDados.Columns[4].Header = "Alternativo 2";
}
}
catch (Exception ex)
{
MessageBox.Show("Erro: " + ex.Message);
}
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
AtualizaPeca ap = new AtualizaPeca();
ap.Show();
}
//Seta os dados no textbox
private void Button_Click_5(object sender, RoutedEventArgs e)
{
AtualizaPeca ap = new AtualizaPeca();
ap.Show();
ap.txtCodigo.Text = GridDados.SelectedItem.ToString();
}
}
What have you done? Can you put some of your source code? So we can understand what has already been done, and help you better.
– brazilianldsjaguar