简体   繁体   中英

How to get the Cell Position of a TableLayoutPanel for a radioButton

Here is my code, it is returning (-1, -1) as the coordinates of the cell position. Which I assume means the control was not found in the table. My radio buttons are sitting inside a panel within the table cell. However, radio.Container returns null.

private void radio_CheckedChanged(object sender, EventArgs e)
{
    var radio = sender as RadioButton;
    var coord = tblPanel.GetPositionFromControl(radio);//returns (-1, -1)
}

I would like to get the row number from the sender object by any means necessary. Thanks for any help you can provide.

Daniel

Turns out what I needed was the parent property which in this case was the panel. Container was always null.

private void radio_CheckedChanged(object sender, EventArgs e)
{
        var radio = sender as RadioButton;
        var row = tblPanel.GetRow(radio.Parent);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM