<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4372482170201062366</id><updated>2024-10-25T00:20:05.476-07:00</updated><category term="Binding"/><category term="C#"/><category term="DataGrid"/><category term="DataSet"/><category term="WPF"/><title type='text'>TIntelligence</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://compuroo.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4372482170201062366/posts/default'/><link rel='alternate' type='text/html' href='http://compuroo.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4372482170201062366.post-8692567539118622888</id><published>2016-06-08T04:27:00.002-07:00</published><updated>2016-06-08T04:27:59.219-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Binding"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="DataGrid"/><category scheme="http://www.blogger.com/atom/ns#" term="DataSet"/><category scheme="http://www.blogger.com/atom/ns#" term="WPF"/><title type='text'>Enlazar un dataset a un datagrid y obtener el registro seleccionado en WPF con C#. (Binding DataSet to Datagrid in WPF).</title><content type='html'>Está publicación es para responderle a Fernando Rojas, sobre como hacer un binding de un dataset a un datagrid en WPF, y recueperar la columna seleccionada, esto se verá de la siguiente manera:&lt;br /&gt;
&lt;br /&gt;
1. Enlazar el dataset al grid, para esto es necesario establecer un binding por medio de la propiedad ItemSource, como se muestra a continuación.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;this.dtgDatos.ItemsSource = null;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;this.dtgDatos.ItemsSource = dtsAlumnos.Tables[0].DefaultView;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i style=&quot;font-weight: bold;&quot;&gt;Nota: &lt;/i&gt;&lt;span style=&quot;color: #990000;&quot;&gt;dtsAlumnos &lt;/span&gt;representa el &lt;span style=&quot;color: #990000;&quot;&gt;dataset&lt;/span&gt;, como un &lt;span style=&quot;color: #990000;&quot;&gt;dataset &lt;/span&gt;puede tener muchas tablas se especifica la tabla que desea enlazarse al datagrid.&lt;br /&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;DtgDatos&lt;/span&gt;, representa mi datagrid.&lt;br /&gt;
&lt;br /&gt;
Mi dataset contiene una tabla con 3 campos &quot;id&quot;, &quot;nombre&quot;, &quot;edad&quot;, estos campos son los que obtuve de mi base de datos.&lt;br /&gt;
&lt;br /&gt;
2. Se agrega al datagrid el evento &quot;SelectedChanged&quot; para que cada que se presione una fila del datagrid se muestren los datos en las cajas de texto.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;private void dtgDatos_SelectionChanged(object sender, SelectionChangedEventArgs e)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Validar si se selecciono algun registros del grid.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (this.dtgDatos.SelectedIndex != -1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Se obtiene el registro seleccionado.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DataRowView elementoSeleccionadoObj = this.dtgDatos.SelectedItem as DataRowView;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Se muestran los valores en las cajas de texto.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.txtId.Text = Convert.ToString(elementoSeleccionadoObj[&quot;id&quot;]);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.txtNombre.Text = Convert.ToString(elementoSeleccionadoObj[&quot;nombre&quot;]);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.txtEdad.Text = Convert.ToString(elementoSeleccionadoObj[&quot;edad&quot;]);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Nota&lt;/i&gt;&lt;/b&gt;: &lt;b&gt;DataRowView &lt;/b&gt;es el elemento seleccionado (el registro seleccionado), ese registro tiene campos los cuales se pueden accesar por medio del nombre&amp;nbsp;&lt;span style=&quot;color: #0b5394;&quot;&gt;elementoSeleccionadoObj[&quot;id&quot;]&lt;/span&gt;&amp;nbsp;o por medio del id de la posición&amp;nbsp;&lt;span style=&quot;color: #0b5394;&quot;&gt;elementoSeleccionadoObj[0]&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
* No es conveniente llevar un dataset desde la base de datos hasta el front de la aplicación ya que sn objetos muy pesados, pero es posible sin problemas.&lt;br /&gt;
&lt;br /&gt;
Así se visualizaría la aplicación:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtTysHg8wCeSoa8cxKfd3n3mANHufrABsaf7Q8A8PXRxVd14e3n2HFoL0b2ysd7JAU9cV9mONVG3oCSv63xmS-2DrSTdsdrhWnXnch2-7xIV7a7HSUajP3Emblgk9eJ7X0TSBtnFMibqw/s1600/WPF.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;266&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtTysHg8wCeSoa8cxKfd3n3mANHufrABsaf7Q8A8PXRxVd14e3n2HFoL0b2ysd7JAU9cV9mONVG3oCSv63xmS-2DrSTdsdrhWnXnch2-7xIV7a7HSUajP3Emblgk9eJ7X0TSBtnFMibqw/s400/WPF.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1zUpLN0XwG2pZyrija0U8NFsR7DbwTupK1iDTGWGvj00RKAF5tx8xgw51QpYbbK13o6g2zNIp7pP1YNwU-sxaV2IlqE-bTqOLLKq4S6x8QxJ6O70hyVbbS6CTMlkPXw-uSllnB2dCbH0/s1600/WPF.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;263&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1zUpLN0XwG2pZyrija0U8NFsR7DbwTupK1iDTGWGvj00RKAF5tx8xgw51QpYbbK13o6g2zNIp7pP1YNwU-sxaV2IlqE-bTqOLLKq4S6x8QxJ6O70hyVbbS6CTMlkPXw-uSllnB2dCbH0/s400/WPF.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://compuroo.blogspot.com/feeds/8692567539118622888/comments/default' title='Comentarios de la entrada'/><link rel='replies' type='text/html' href='http://compuroo.blogspot.com/2016/06/enlazar-un-dataset-un-datagrid-y.html#comment-form' title='1 Comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4372482170201062366/posts/default/8692567539118622888'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4372482170201062366/posts/default/8692567539118622888'/><link rel='alternate' type='text/html' href='http://compuroo.blogspot.com/2016/06/enlazar-un-dataset-un-datagrid-y.html' title='Enlazar un dataset a un datagrid y obtener el registro seleccionado en WPF con C#. (Binding DataSet to Datagrid in WPF).'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtTysHg8wCeSoa8cxKfd3n3mANHufrABsaf7Q8A8PXRxVd14e3n2HFoL0b2ysd7JAU9cV9mONVG3oCSv63xmS-2DrSTdsdrhWnXnch2-7xIV7a7HSUajP3Emblgk9eJ7X0TSBtnFMibqw/s72-c/WPF.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4372482170201062366.post-3649646745141872939</id><published>2016-05-05T20:09:00.002-07:00</published><updated>2016-05-05T20:09:40.811-07:00</updated><title type='text'>Página Principal.</title><content type='html'>Hola Amigos, esté sitio solo fue creado para redirigir a nuestra pagina las entradas que ya habíamos craado en compuroo y que fueron pasadas a el nuevo blog. Favor de redirigir a:&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;a href=&quot;http://tintelligence.blogspot.com/&quot;&gt;&lt;b&gt;http://tintelligence.blogspot.com&lt;/b&gt;&lt;/a&gt;&lt;/h2&gt;
</content><link rel='replies' type='application/atom+xml' href='http://compuroo.blogspot.com/feeds/3649646745141872939/comments/default' title='Comentarios de la entrada'/><link rel='replies' type='text/html' href='http://compuroo.blogspot.com/2016/05/pagina-principal.html#comment-form' title='0 Comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4372482170201062366/posts/default/3649646745141872939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4372482170201062366/posts/default/3649646745141872939'/><link rel='alternate' type='text/html' href='http://compuroo.blogspot.com/2016/05/pagina-principal.html' title='Página Principal.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>