System.Windows.Forms.DataGrid - dont allow to add new rows! (newby)

E

elime

Hi all

I load datas from an SQL server to a Datagrid. The datagrid columns are
basically read only but one column is not -> the checkboxcolum. The
user needs to be able to check or uncheck this column for selection.

Now at the end of the datagrid (last row) there is another row with a *
in front of it. Once a user clicks on that, at the position of the
checkboxcolumn, it'll add a new row to the datagrid with NULL values.
You can even add more such NULL-Value-rows by clicking again on the
same position of the new row etc...

Even if nothing can happen (the datacolumns are read only, nothing goes
back to the database) it still looks stupid on the grid. Can I somehow
prevent this? Is there anything like "AllowNewRows=false" or something?

Any help would be great, that row gets on my nerves :(
It doesn't look user-friendly and I need to get to this user-friendly
point with my project (its ad iploma project for my study)

Thanks
Elime
 
M

Morten Wennevik

Hi elime,

If you run the data through a DataView, you can use the DataView.AllowNew property to get rid of the New line.
 
E

elime

Hi Morten!

Thanks for your quick response!!

Unfortunately is the project nearly finished (we are in the
makeup-phase) and we did not set up a DataView-Object for the
databinding. We created SQL-Views but not DataViews and those SQL-Views
are directly loaded into the dataSet which is our DataSource of the
Grid.

As there are many functions in our project that base on that kind of
binding, it would cost a lot of work to re-configure the project to
have a DataView. In fact, it's only a "make-up" change and we decided
to not have this Big change for that.

Is there any other possibility to prevent the adding of new rows
directly in the dataset or the grid?

If not I guess we have to accept it :(

Thanks very much!!
Elime
 
E

elime

For all that read this and have the same problem:

If you dont work with a seperate dataview-object but want to prohibit
new rows, there is still the possibility of disallow it:

The DataSet has a default-Value "DefaultView" (dataset.defaultview)
which always gives you a dataview of your datatables of the grid. So if
you don't use any special dataview object you can disallow adding new
rows on this default-view:

You can say AllowNew=false (dataset.defaultview.allownew=false) and
your grid will lock the datas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top