checkbox inside gridview

Welcome Forums General PowerShell Q&A checkbox inside gridview

Viewing 3 reply threads
  • Author
    Posts
    • #161198
      Participant
      Topics: 21
      Replies: 32
      Points: 309
      Rank: Contributor

      hi all,

      in my GUI, I have a datagridview to display some information to the user. That datagrid has 2 columns;

      a DataGridViewCheckBoxColumn and a DataGridViewTextBoxColumn

      I need to read the value into the text cell whenever a user clicks in the checkbox to make his selection.

      I am unable to retrieve the value of the text cell when the checkbox value changes to $True.

      here’s my try of it;

          $datagridNotMembers_Click = {
              $rowIndex = $datagridNotMembers.SelectedCells.RowIndex
              $Name = $datagridNotMembers.Rows[$rowIndex].Cells[1].Value
              if ($datagridNotMembers.Rows[$rowIndex].Cells[0].Value -eq $True){
                  Out-File -FilePath c:\Temp\nametest.txt -InputObject $Name
              }
          }
      

      if I get the value of $datagridNotMembers.Rows[$rowIndex].Cells[0].Value, it is empty. how can I check if the checkbox is checked or not?

      thank you!

    • #161255
      Senior Moderator
      Topics: 9
      Replies: 1236
      Points: 4,443
      Helping Hand
      Rank: Community Hero

      how can I check if the checkbox is checked or not?

      If $checkbox is the object defined for CheckBox,you would use $Checkbox.Add_CheckStateChanged({‘whatever code here’}) event handler here when user clicks and $CheckBox.Checked to see whether it is in checked state or not.

    • #161412
      Participant
      Topics: 21
      Replies: 32
      Points: 309
      Rank: Contributor

      DataGridViewCheckBoxColumn

      looks like you didn’t read my post correctly.

      it’s not a checkbox object, it’s a column into a datagridview defined as DataGridViewCheckBoxColumn

      I am still unable to get the status of that cell, which contains a checkbox, when it is checked or not.

      thanks!

    • #161598
      Participant
      Topics: 24
      Replies: 175
      Points: 587
      Helping Hand
      Rank: Major Contributor

      assuming your checkbox is in the first column

      if ($DataGridViewRow.Cells[0].Value)
      {
      do something
      }
      
Viewing 3 reply threads
  • The topic ‘checkbox inside gridview’ is closed to new replies.