Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify data grid view columns with data table bindings

I have binded DataTable to DataGridView (in WinForms) and i'd like to change how columns are formatted in GUI.

However, if i manually add columns to DataGridView and set errorsGrid.AutoGenerateColumns = false, data doesn't appear in those columns (rows are added however). So is there any way to bind DataTable and change eg. width of column in DataGridView? With AutoGenerateColumns = false bindings like BingingList are added to existing columns, but DataTable doesn't seem to work that way.

like image 317
savpek Avatar asked Feb 23 '26 06:02

savpek


1 Answers

Please tell have you specified DataPropertyName attribute for each of columns you have added manually on Edit Columns form for your grid (as on screenshot below)?

enter image description here

Looks like you need to specify binding to table columns explicitly for each of your grid columns on form Edit Columns which is invoked by right-click menu item Edit Columns... for grid view in form editor. You need to configure data binding for each column manually, as you have specified grid's property errorsGrid.AutoGenerateColumns = false (which means columns with bidings to table fields will not be generated automatically). As grid contains empty rows - you can be sure that data is loaded successfully, and the only thing which remains to do - is to configure way how rows are displayed in the grid.

like image 91
Andrii Kalytiiuk Avatar answered Feb 24 '26 21:02

Andrii Kalytiiuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!