After seeing some code it is still not entirely clear what you are doing (for example, what is racking
?), but this should help anyway...
TableLayoutPanel
has a method called GetControlFromPosition
which will get the control within a given cell (column and row), so firstly you can get that control like so:
var myCellControl = tableLayoutPanel1.GetControlFromPosition(col, row);
What you do next will depend on how you are adding your controls. If you are directly adding a Rack
control to each cell, then you can just test it like so:
if(myCellControl is Rack)
{
//is Rack control, so do someting
}
otherwise, if the Rack
control is nested within a container control (e.g. a Panel
), then you should loop the children controls and test for a Rack
control:
bool hasRack = false;
foreach(Control child in myCellControl.Controls)
{
if(child is Rack)
{
//Rack control found
hasRack = true;
break;
}
}
Hope that helps