Truco: Llenar los datos de un DataGridView en TextBox detallados en C#
Hola internautas programadores y demas aca les dejo un truco que busque mucho en la web y pues termine resolviendo el problema con la pagina de MSDN la cual recomiendo mucho el truco es bien sencillo.
DataRow.Item (Propiedad) (String)
http://msdn.microsoft.com/es-es/library/146h6tk5%28v=VS.80%29.aspx
private void DataGrid1_Click(
object sender, System.EventArgs e)
{
// Get the DataTable the grid is bound to.
DataGrid thisGrid = (DataGrid) sender;
DataTable table = (DataTable) thisGrid.DataSource;
DataRow currentRow =
table.Rows[thisGrid.CurrentCell.RowNumber];
// Get the value of the column 1 in the DataTable.
Console.WriteLine(currentRow["FirstName"]);
// You can also use the index:
// Console.WriteLine(currentRow[1]);
}
Acá mismo tenemos el código solo procedemos a en el datagrid ir al evento click y en esta parte del código: Console.WriteLine(currentRow["FirstName"]); Lo podríamos personalizar y cambiarlo a:
Textbox1.text = currentRow[“Nombre de la columna que deseas del data grid”]
Esto permitirá que a lo que se haga un click en algún campo el inmediatamente te traiga los datos al textbox que desees por campo si son dos campos seria:
Textbox1.text = currentRow[“Nombre de la columna que deseas del data grid”]
Textbox2.text = currentRow[“Nombre de la columna que deseas del data grid”]
y Listo espero le guste:
OJO: SI no estas usando un datagrid si no específicamente un datagridView debemos cambiar la siguiente línea de código: DataGrid thisGrid = (DataGrid) sender;
Y quedaría de la siguiente forma: DataGridView thisGrid = (DataGridView)sender;
Al final el código quedaría así para que solo copien y pequen y cambien su valor
private void datagridview1_Click(object sender, EventArgs e)
{// Obtener el DataTable se une a la red.
DataGridView thisGrid = (DataGridView)sender;
DataTable table = (DataTable)thisGrid.DataSource;DataRow currentRow =
table.Rows[thisGrid.CurrentCell.RowIndex];
// Obtener el valor de la columna 1 Y 2 en el DataTable.
string idsite = "";
string idprefijo = "";textbox1.text = currentRow["CAMPO1"].ToString();
textboxn.net = currentRow["CAMPON"].ToString();
}
Luego les hare un ejemplo Gracias espero les sirva.





