When manipulating DataGridView cells, you typically do:
MyGrid.CurrentRow.Cells["EmployeeFirstName"].Value = "John";
which is all fine and dandy, but as complexity rises, you start worrying about spelling errors, refactoring issues etc.
Historically, I just made the columns public so I could access them directly in the class instance, but I then have to fight the Windows Forms designer which wants to keep them private (supposedly because it's good practice).
My current solution is to have a class called Cols, with a bunch of strings:
public static class Cols
{
public static string EmployeeFirstName = "EmployeeFirstName";
...
}
Which results in this:
MyGrid.CurrentRow.Cells[Cols.EmployeeFirstName].Value = "John";
This gives me some IntelliSense goodness as opposed to waiting for a runtime error. It still seems vaguely hack-ish, though.
Is there an even more convenient way to do this?