开发者

Best way to get a handle to the DataGridViewColumn when using autogeneratecolumns

开发者 https://www.devze.com 2023-01-26 19:22 出处:网络
Im using a datagridview with autogeneratecolu开发者_JAVA技巧mns on. I can use something like this to get a handler to a particular column:

Im using a datagridview with autogeneratecolu开发者_JAVA技巧mns on. I can use something like this to get a handler to a particular column:

public int MyProperty { get; set;}

....

myDataGridView.Columns["MyProperty"];

Which is not optimal (it means that if I change the name of MyProperty I need to change all the "MyProperty" strings in the code). Is there a way to overcome this problem? Can I, for example, use an attribute to make the column identifier independent of the property name (without resorting to manual columns creation)?


One easy way is to make use of an expression which can evalaute the property and essentially give you the strong typing ability so that should you re-factor your property name it will propagate.

A sample can be found here...as it is very common for this to surface when implementing INotifyPropertyChanged as the loose typing surfaces there as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号