Datagrid formatting
-
Hi! Is it possible to hide columns in the datagrid? When using the original setup of the datagrid every column is displayed. And if you would like to populate the datagrid with information from a database, it displays the primary key and foreign key columns as well. Is there a way to hide an arbitrary column in the datagrid, but still being able to reach the value of the it behind the scenes? Thank you! :)
-
Hi! Is it possible to hide columns in the datagrid? When using the original setup of the datagrid every column is displayed. And if you would like to populate the datagrid with information from a database, it displays the primary key and foreign key columns as well. Is there a way to hide an arbitrary column in the datagrid, but still being able to reach the value of the it behind the scenes? Thank you! :)
Sounds like you need to look into using the DataView. Research to see if it fits your needs, then ask again if you need more info. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek. -
Hi! Is it possible to hide columns in the datagrid? When using the original setup of the datagrid every column is displayed. And if you would like to populate the datagrid with information from a database, it displays the primary key and foreign key columns as well. Is there a way to hide an arbitrary column in the datagrid, but still being able to reach the value of the it behind the scenes? Thank you! :)
Yes, check the
DataGridTableStyle
class. The basic idea is that you create oneDataGridTableStyle
object, and then addDataGridTextBoxColumn
or other column types (check boxes por example) to the table style, only for the columns you want to display (use the MappingName property). Here's an example, from some code I'm working on right now:DataGridTableStyle style = new DataGridTableStyle(); style.MappingName = dtZoneCollectors.TableName; DataGridTextBoxColumn textCol = new DataGridTextBoxColumn(); textCol.MappingName = "column_name"; textCol.HeaderText = "Name as it will appear to the user"; textCol.Width = 200; textCol.ReadOnly = true; style.GridColumnStyles.Add(textCol); gridCollectors.TableStyles.Add(style);
It only adds one column, but hopefully you'll get the idea. Good luck! -- LuisR
Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!
-
Hi! Is it possible to hide columns in the datagrid? When using the original setup of the datagrid every column is displayed. And if you would like to populate the datagrid with information from a database, it displays the primary key and foreign key columns as well. Is there a way to hide an arbitrary column in the datagrid, but still being able to reach the value of the it behind the scenes? Thank you! :)