I am trying to convert a DataGridView cell to a control:
Control dat = new Control();
dat = Convert.ChangeType(dataGridView1[colIndex,rowIndex], typeof(Control));
I am fetching the values of colIndex and rowIndes from a index code. The problem is even though I tried many codes to convert, it does not work.
The exception I am getting is:
Can not implicitly convert an object to a control. An explicit convertion exist(are u missing a cast?)
To access the control that is hosted by a
DataGridViewCellyou use theEditingControlproperty of the cell when the cell is in editing mode.This property returns a
System.Windows.Forms.Control.You can also get at the control within the
DataGridViewEditingControlShowingevent – theControlproperty ofDataGridViewEditingControlShowingEventArgsis of typeSystem.Windows.Forms.Control.If you want to access the control at other times then (I believe) you are out of luck – I say that based mainly on this quote from the MSDN docs on
DataGridViewEditingControlShowing: