I want to get the value of the UserID cell that has the following settings made with Visual Studio 2017 in a window (WPF)
<DataGridTextColumn Binding="{Binding Path=idUsuario}" ClipboardContentBinding="{x:Null}" Header="idUsuario" HeaderStringFormat="idUsuario" Visibility="Hidden"/>
Since the user does not have to see the id I put it hidden, the user selects a row that has the registration data. Through a button you will get the id of that record to use it later.
the code of the filling is the following made with C #
public void llenadoDataGrid()
{
String consulta = "select idUsuario,Nombre,ApellidoP ,ApellidoM ,Sexo,Telefono,Edad,Puesto from usuarios;";
SqlDataAdapter dataAdapter = new SqlDataAdapter(consulta, new BaseDeDatos().obtenerConexion());
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
DataTableCollection collection = ds.Tables;
DataTable table = collection[0];
foreach (DataRow row in table.Rows)
{
var data = new PruebaDeLLenadoDataGrid {idUsuario = row["idUsuario"].ToString(), Nombre = row["Nombre"].ToString(),
ApellidoP = row["ApellidoP"].ToString(), ApellidoM = row["ApellidoM"].ToString(),
Sexo = row["Sexo"].ToString(), Telefono = row["Telefono"].ToString(),
Edad = row["Edad"].ToString(), Puesto = row["Puesto"].ToString() };
dataGridUsuarios.Items.Add(data);
}
}
The other class I use called TestDataGridDataGrid have the following
lass PruebaDeLLenadoDataGrid
{
public String idUsuario { get; set; }
public String Nombre { get; set; }
public String ApellidoP { get; set; }
public String ApellidoM { get; set; }
public String Sexo { get; set; }
public String Telefono { get; set; }
public String Edad { get; set; }
public String Puesto { get; set; }
}