i am trying to use Enum as a Datagridview Coloumn index, but failed
My Enums
enum _EnmDgvCol
{
SrNo,
Name,
Qty,
Rate,
Amount,
}
and I am trying to as follows:
MydataGridView[_EnmDgvCol.Name, 0].Value = "Some Value";
but its giving Error
The best overloaded method match for 'System.Windows.Forms.DataGridView.this[int, int]' has some invalid arguments
if i use following code its works
MydataGridView[1, 0].Value = "Some Value";
My Question is How to Use Enums instead of column index
Type cast the enum
value to int
for instance you have _EnmDgvColInstance
that has value as _EnmDgvCol.Name
_EnmDgvCol _EnmDgvColInstance = _EnmDgvCol.Name;
MydataGridView[(int)_EnmDgvColInstance, 0].Value = "Some Value";
Or simply
MydataGridView[(int)_EnmDgvCol.Name, 0].Value = "Some Value";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With