Question

I have tried many things to get around this problem and I cannot seem to find the right answer.

I have a DataGrid with 6 Columns, and the user should only be redirected to the other page when they click on any row on Column 6.

enter image description here

So the user can only click on any of the Cells under To-Do. When they click on that row I need it to find the Type which is in the same row as that cell. E.G if I clicked the 6 To-Do, It should know I have clicked on the row type Football.

I want this then to pass the Type that's in the first column to another page so I can bring up all the different To-Do items under that Type.

This is what I tried:

        cSViewEntity selectedView = dgFake.SelectedItem as cSViewEntity;

        AllocateAudits page = new AllocateAudits()
        {
            DataContext = selectedView
        };
        FrameNavigation.Navigate(page);

But when I did this it doesn't hit this method:

    public void Page_OnNavigatedTo(object sender, NavigationEventArgs e)
    {

        var newDataContext = e.Content;

        _View = (cSViewEntity)newDataContext;

        _Transactions = new List<cAuditTransactionTypeEntity>();

        _Transactions = sp.GetTransactionTypes().ToList();

         string TransactionType = _View.TransactionType;

        int TransactionTypeID = _Transactions.FirstOrDefault(w => w.TransactionType == TransactionType).TransactionTypeId;

        dgAllocate.ItemsSource = sp.GetTransactionsNotEvaluated(TransactionTypeID).ToList();
    }

Any help would be very helpful,

Thanks.

ANSWER TO QUESTION:

I passed the SelectedItem to the other page, then found the Type on that page and ran a Stored Procedure on that Type.

cSViewEntity obj = (cSViewEntity)dgFake.SelectedItem;
     AllocateAudits page = new AllocateAudits(obj)
     {
         DataContext = obj
     };
         FrameNavigation.Navigate(page);
     }

And then you pass it to the constructor and then in the start of your method you add this.

 private void Rawr(cSViewEntity obj)
 {
      var transactiontype = _obj.TransactionType;

      //Stores the information from newDataContext to the entity with the name of _View.
      _View = (cSViewEntity)obj;

No correct solution

OTHER TIPS

For the last column (column6) I would suggest you create a Datagrid templateCell.

for example :

<DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" >
 <DataGrid.Columns>
  <DataGridTemplateColumn Header="To Do" >
   <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
     <Button x:Name="MyNavigationButton" Content="{Binding ToDo}" Click="MyClickEvent"/>
    </DataTemplate>
   </DataGridTemplateColumn.CellTemplate>
  </DataGridTemplateColumn>
 </DataGrid.Columns>
</DataGrid>

in Code Behind, run the MyClickEvent

private void MyClickEvent(object sender, EventArgs e)
{
 var myBTNData = ((Button)sender).DataContext;

 //here does follow your code based on the myBTNData
}

Hope it gets you started. You also can use other elements (like a hyperlink)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top