---
title: "Selecting a row in DataGrid"  
description: "Selecting a row in DataGrid"  
author: "Anonymous User"  
published: 2014-02-02  
updated: 2014-02-03  
canonical: https://www.mindstick.com/forum/1939/selecting-a-row-in-datagrid  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Selecting a row in DataGrid

I defined an initial [Table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) with three rows. If a [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) a row and clicks a "Start new Table" [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net), it will open a new tabItem with a new Table. the [Problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is that i dont know how can i select an [entire row](https://answers.mindstick.com/qa/46828/if-i-buy-an-entire-row-of-seats-on-a-long-flight-so-no-one-is-next-to-me-can-the-airline-sell-one-of-my-empty-seats-to-someone-or-will-they-respect-the-fact-that-the-empty-seats-are-mine-to-do-as-i-p) in my DataGrid.

**[C# Code](https://www.mindstick.com/forum/403/how-to-export-data-in-excel-file-from-sql-server-using-c-sharp-code):**

```
//this my initial Tableprivate ObservableCollection<TableDataRowStringItem> tableobject = new ObservableCollection<TableDataRowStringItem>();List<TableDataRowStringItem> rowstringList = new List<TableDataRowStringItem>();TableDataRowStringItem item = new TableDataRowStringItem();item.RowNumber = 1; item.saveFlag = true; item.ObjectType = "E"; item.Name = "E"; item.PredecessorRowNumber = "0";rowstringList.Add(item);item = new TableDataRowStringItem();item.RowNumber = 2; item.ObjectType = "Function"; item.Name = "Function";    item.PredecessorRowNumber = "1";rowstringList.Add(item);item = new TableDataRowStringItem();item.RowNumber = 3; item.ObjectType = "E"; item.Name = "E"; item.PredecessorRowNumber = "2";rowstringList.Add(item);rowstringListEPK = rowstringList;for (int i = 0; i < rowstringList.Count; i++){    tableobject.Add(rowstringList[i]);}DataGrid1.ItemsSource = tableobject;//Button Codeforeach (TableDataRowStringItem item in rowstringListEPK){    if (item.ObjectType == "Function" **(&& Hier i schould write if row.Isselected)**)    {       rowStringItem.Name = item.Name;       tabControl.Items.Add(tabItem);       tabItem.Focus();       tabItem.IsSelected = true;       tabItem.Header = rowStringItem.Name;       TableTab.Visibility = Visibility.Visible    }    else do nothing}//XAML Code <DataGrid.RowStyle>    <Style TargetType="DataGridRow">        <Style.Triggers>            <Trigger Property="IsSelected" Value="True">               <Setter Property="BorderBrush" Value="Blue" />               <Setter Property="BorderThickness" Value="1" />               <Setter Property="AllowDrop" Value="True" />            </Trigger>        </Style.Triggers>    </Style> </DataGrid.RowStyle>
```

## Replies

### Reply by Pravesh Singh

Hi Ankita,\

This may help:

```
<DataGrid SelectionMode="Single" SelectionUnit="FullRow" ...orDataGrid dataGrid = new DataGrid();dataGrid.SelectionUnit = DataGridSelectionUnit.FullRow;dataGrid.SelectionMode = DataGridSelectionMode.Single;
```


---

Original Source: https://www.mindstick.com/forum/1939/selecting-a-row-in-datagrid

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
