问题
Hai all, Am using devexpress XtraGrid in C#.NET application.On run time i want to hide 1 column of XtraGrid and access that column in code behind page.And please help to access rows and columns of XtraGrid.
Thank You
回答1:
You should use the View.Columns[someFieldName].Visible property to hide / show a column. Please also refer to the following topic:
http://documentation.devexpress.com/#WindowsForms/CustomDocument753
回答2:
To hide a column from user set columns visible property to False as mentioned above.
However this puts the hidden column in SelectColumn Menu which user can access at run time.
Right Click Grid Header -> Click Select Columns -> Choose hidden column from small window -> Drag it to the Grid.
In this case your hidden columns will be available to user. There are two possible solutions to avoid above Situation:
In Addition to setting visible property of Column also set OptionColumn.AllowShowHide to False. This will make sure that this column will not Pop up in column select window.
Other solution should be used only when you want to give absolutely no right to the user for changing the layout of the grid. This can be done by Setting GridView's property - OptionMenu->EnableColumnMenu to False. However after setting this user will be restricted from all other layout Options also like Groupping, filter, search etc.
回答3:
Try this: ColumnName.Visible=False;
回答4:
Ok. I did this to indefinitely hide ALL my xtraGrid columns so I can select the few I can show (make visible true).
int myCount;
try { myCount = this.gridView2.Columns.Count; }
catch { myCount = 0; }
for (int j = 0; j < myCount; j++)
{
this.gridView2.Columns[j].Visible = false;
}
Hope it helps.
来源:https://stackoverflow.com/questions/3615415/how-to-hide-column-of-devexpress-xtragrid