Newbie here so not sure what are the potential performance issues here, and what are the best practices.
Is this a good idea? Thoughts?
FROM THIS:
(prone to manual error when cells codes are all over the place and/or gridview changes)
row.Cells[1].Visible = false; // CustomerId
row.Cells[9].Visible = false; // OrderNumber
row.Cells[10].Visible = false; // ProductId
. . .
int matchId = row.Cells[11].Text;
. . .
TO THIS:
(more readable and manageable, just make sure the enum is in sync with the gridview)
row.Cells[Col.CustomerId.GetVal()].Visible = false;
row.Cells[Col.OrderNumber.GetVal()].Visible = false;
row.Cells[Col.ProductNumber.GetVal()].Visible = false;
. . .
int matchId = row.Cells[Col.CustomerName.GetVal()].Text;
. . .
public enum Col
{
MatchId = 1,
. . .
ServiceCode = 9,
CustomerId = 10,
CustomerName = 11,
. . .
}
public static class ColExt
{
static public int GetVal(this Col col)
{
return (int)col;
}
}
In my opinion the code is more readable with the enums. But it’s important that you have a code generator for the enum(s). Otherwise you do a lot of misstakes, if you have many columns to handle.