Skip to content

Instantly share code, notes, and snippets.

@RicardoACS
Created July 24, 2016 23:38
Show Gist options
  • Save RicardoACS/41569fb25c5dd3b6f4792f38c6004fc0 to your computer and use it in GitHub Desktop.
Save RicardoACS/41569fb25c5dd3b6f4792f38c6004fc0 to your computer and use it in GitHub Desktop.
public IEnumerable<DataGridRow> obtenerDataGridRows(DataGrid grid)
{
var itemsSource = grid.ItemsSource as IEnumerable;
if (null == itemsSource) yield return null;
foreach (var item in itemsSource)
{
var row = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
if (null != row) yield return row;
}
}
private void dataGrid_Trips_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
DataTable dt = new DataTable();
dt = ((DataView)dataGrid_Trips.ItemsSource).ToTable();
var row_list = obtenerDataGridRows(dataGrid_Trips);
foreach (DataGridRow single_row in row_list)
{
if (single_row.IsSelected == true)
{
textboxSearchClient.Text = dt.Rows[single_row.GetIndex()].ItemArray[0].ToString();
}
}
}
catch (Exception)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment