Additional blank rows in datagridview

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 3 years and 4 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
HadleysHope
Posts: 5
Last visit: Thu Aug 24, 2023 9:25 am

Additional blank rows in datagridview

Post by HadleysHope »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build:5.8.187
Operating system: Windows 10
PowerShell version(s): 5.1.14393.2828

*** Please add details and screenshots as needed below. ***
Hey all, im new to using datagridview and datatables. I have a datagridview with a datatable as its source, when I add my first entry to the datatable the datagrid view inserts the line as well as a blank line (thus showing two blank lines as well as the data entered).

Can anyone tell me whats going on or how to remove the additional line? I thought at first that the line was on the datatable but with some troubleshooting the additional line is on the datagridview.

Any help, greatly appreciated.

Image
Attachments
blankrows.png
blankrows.png (4.05 KiB) Viewed 1822 times
HadleysHope
Posts: 5
Last visit: Thu Aug 24, 2023 9:25 am

Re: Additional blank rows in datagridview

Post by HadleysHope »

I may have solved this or at least worked around the issue. I was assigning the datatable as the source for the datagridview before the datatable had any entries and just headers, adding a row and then assigning as the source for the datagrid view seems to have solved my issue (or, again, provided a work around).
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Additional blank rows in datagridview

Post by jvierra »

When creating a DataTable you must use either auto-columns or fixed columns assigned to match the table field names in the properties designer of the column as the data member name. Any other approach will give you odd results. YOU cannot both add columns and assign a table or there will be no way to match the fields.

A table can be assigned and empty and it will either bind to the specified columns or generrate the columns according to the field names. You can then add rows to teh table as needed and they will display in the grid.
If the grid allows adding new rows directly then it will always have an extra blank row for adding data. To not have the blank row just uncheck the property that allows adding a new row.
This topic is 3 years and 4 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked