Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Databind List Of Objects To A WinForms DataGridView, But Not Show Certain Public Properties

I'm not even sure if i'm doing this correctly. But basically I have a list of objects that are built out of a class. From there, I am binding the list to a datagrid view that is on a Windows Form (C#)

From there, it shows all the public properties of the object, in the datagrid view. However there is some properties that i still need accessible from other parts of my application, but aren't really required to be visible in the DataGridView.

So is there an attribute or something similar that I can write above the property to exclude it from being shown.

P.S. Im binding at runtime. So i cannot edit the columns via the designer.

P.P.S. Please no answers of just making public variables (Although if that is the only way, let me know :)).

like image 502
MindingData Avatar asked Mar 12 '10 23:03

MindingData


People also ask

What is difference between DataGridView and DataGrid control in Winforms?

The DataGrid control is limited to displaying data from an external data source. The DataGridView control, however, can display unbound data stored in the control, data from a bound data source, or bound and unbound data together.

What is DataGridView data binding?

The DataGridView control supports the standard Windows Forms data binding model, so it can bind to a variety of data sources. Usually, you bind to a BindingSource that manages the interaction with the data source.

Which is a property of the DataGridView control?

The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor.

What is BindingSource C#?

The BindingSource component acts as an intermediary that provides binding and currency management services. At design time or run time, you can bind a BindingSource component to a complex data source by setting its DataSource and DataMember properties to the database and table, respectively.


1 Answers

Add [Browsable(false)] attribute to the public properties that you do not want to generate column for.

like image 84
Vivek Avatar answered Oct 08 '22 15:10

Vivek