0

I'm using a DataGridView in a WinForm for the very first time, and have run into an odd problem.

I'm trying to populate the DataGridView control from the database. I'm not binding it to a dataset or anything, but retrieving a set of rows from a Sqlite query. I am then populating the rows programmatically from the data retrieval result. The grid is set up like this (as it appears in the designer):

enter image description here

What happens at runtime is fine, except for what appears to be a "phantom" row, which shows up in the grid as it appears in the designer, as the last row (blank or unpopulated), when I finish loading the grid. I've tried clearing the rows:

DataGridView.Rows.Clear();

But this doesn't clear anything. Trying to remove or make this row invisible fails with an exception because it's apparently uncommitted.

How do I get rid of the thing?

Cyberherbalist
  • 12,061
  • 17
  • 83
  • 121
  • 2
    Possible duplicate of [How to disable the last blank line in DatagridView?](https://stackoverflow.com/questions/3665048/how-to-disable-the-last-blank-line-in-datagridview) – Ňɏssa Pøngjǣrdenlarp Apr 24 '18 at 17:54
  • @Plutonix, I wish SO's search system could find these questions that have been already answered. I thought I looked all over SO, but never saw that one. Maybe my search skills are poor... :-( – Cyberherbalist Apr 26 '18 at 18:30

1 Answers1

0

After entering the question in its entirety, I tried one last time to see if there was something that stood out. So I examined the properties of the DataGridView in close detail and wondered about some of the properties whose function I wasn't sure about.

The answer turned out to be the property AllowUserToAddRows. The "uncommitted row", as the exception designated it, is the place where the user would add the information for a new row that is to be inserted! Since this implementation of the grid is intended to be for editing of existing rows only, setting this property to False removed the apparently "bogus" row, and solved my problem.

And incidentally removed the row from the designer.

Cyberherbalist
  • 12,061
  • 17
  • 83
  • 121