I have the textbox in datagrid. Data are taking from database. assume I have 10 rows with these textbox value. once I click on this row, able to get this selected row index. My goal is if once textbox value are get change, I need to detect which row it is (which value)and do some calculation based on this value then need to display another field of the same row. So I am in a position to know which row being get hit. `I am using Datagrid with following declarations:
<dg:DataGrid Name="dgBudgetAllocation" CanUserDeleteRows="False" CanUserAddRows="False" CanUserSortColumns="True"
IsSynchronizedWithCurrentItem="True" MaxHeight="400" RowHeight="70" SelectionUnit="Cell" SelectedValue="" SelectionMode="Single"
AutoGenerateColumns="False" GridLinesVisibility="None" HeadersVisibility="Column" PreviewMouseDown="DgBudgetAllocation_OnPreviewMouseDown" SelectedCellsChanged="DgBudgetAllocation_OnSelectedCellsChanged" MouseDown="DgBudgetAllocation_OnMouseDown" PreviewMouseUp="DgBudgetAllocation_OnPreviewMouseUp" PreviewKeyDown="DgBudgetAllocation_OnPreviewKeyDown" HorizontalAlignment="Left">
<dg:DataGridTemplateColumn Header="Budget Type" SortMemberPath="BUDGETYPE"
MinWidth="50" HeaderStyle="{DynamicResource dgHeaderLeftJust}" CellStyle="{DynamicResource dgColumnRightJust}">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding BUDGETYPE}" HorizontalAlignment="left" VerticalAlignment="Top" Margin="0,0,3,0" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
I have tried the following snippet based on various person suggestion. for all I am getting the selected index is -1.
DataRowView drv = (DataRowView)dgBudgetAllocation.SelectedItem;
object item = dgBudgetAllocation.SelectedItem;
string ID = (dgBudgetAllocation.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;
DataGrid row1 = (DataGrid)dgBudgetAllocation.SelectedItems[1];
var row = dgBudgetAllocation.SelectedItems[0];
Nothing is working. Please suggest me how to proceed further .