md.Rayad 14 Newbie Poster

I have a powershell script in that script i am using datagridview. My script is working fine. All looks ok to me.

My issue is i want to get the first column value of selected row. To fulfill this i need to add event (cell click/cell content click/cell mouse click). I am not able to figure it out. How to add event.

Can somebody please advise me on this?

 $datagridview1_CellMouseClick = [System.Windows.Forms.DataGridViewCellEventHandler]{

write-host $_.RowIndex # This displays the row number selected
write-host $_.ColumnIndex # This displays the column number selected
write-host $datagridview1.Rows[$_.RowIndex].Cells[0].value # This would display the value of the first cell in the selected row
write-host $datagridview1.Rows[$_.RowIndex].Cells[$_.ColumnIndex].value # This would display the value of the cell selected
}