0
votes

The last column in my Datagrid is hyperlinked, every cell has an individual hyperlink. I want to be able to click on a cell, get the data within that cell, and using the hyperlink, redirect to another form, passing that data selected.

string AuditsRequired = (dgFake.Items[0] as DataRowView).Row.ItemArray[5].ToString();
        xamlAllocteAudits AA = new xamlAllocteAudits(AuditsRequired);
        AA.Show()

This is my first attempt at fetching the cell-data, however due to the code, I have specified a column and row, whereas I want the cell to be which ever cell I click, rather than specifying in code.

Here is my datagrid, showing the cells that have been hyperlinked: http://i.stack.imgur.com/v7Uyw.png

1

1 Answers

0
votes

If i understand your question correctly, you want to click on a cell and obtain the data from that cell. I suspect that the cellclicked event or currentcellchanged event are going to be the most useful to you for this task.

you could try something like

 private void dgFake_CurrentCellChanged(object sender, EventArgs e)
    {
     int row = e.row;
     int col = e.col;
  if e.value !=null
  {
     string AuditsRequired = dgfake[row,col].value.tostring();
     xamlAllocteAudits AA = new xamlAllocteAudits(AuditsRequired);
     AA.Show()
  }

 }

You may or may not know this, but you can get VS to make this event method (or any event method) for you by clicking on the object (in your case the datagridviewer) in the designer and then clicking the events (little lightning bolt) icon in the properties window.

Hope that helps.

Cheers.