checkbox inside gridview

Welcome Forums General PowerShell Q&A checkbox inside gridview

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 months ago.

  • Author
    Posts
  • #161198

    Participant
    Topics: 8
    Replies: 10
    Points: 124
    Rank: Participant

    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: 8
    Replies: 1041
    Points: 3,440
    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: 8
    Replies: 10
    Points: 124
    Rank: Participant

    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: 23
    Replies: 154
    Points: 368
    Helping Hand
    Rank: Contributor

    assuming your checkbox is in the first column

    if ($DataGridViewRow.Cells[0].Value)
    {
    do something
    }
    

The topic ‘checkbox inside gridview’ is closed to new replies.