I am naming each column in a datagridview using a right-click menu with all the names the user can use. As each name is used, I have disabled the right-click menu item for each name as it is selected so that the user cannot name two columns the same. To do this, I am using a simple if statement to see if that column name exists:
if (MyDataGridView.Columns["ColName"] != null)
{
ColName.Enabled = false;
}
However, if the user wants to re-name a column, I am having trouble "un-naming" the column, as the above if statement returns true for both names after I re-name the column. Is there a way to clear a column name so that a column doesn't have multiple names associated with it?
这应该工作:
MyDataGridView.Columns["ColName"].Name = string.Empty
使用DisplayName属性在您的datagridview中指定列名称会更加合适。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.