|
-
Mar 18th, 2007, 06:41 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Adding new records to a datagrid
Hi, I want to disallow the user from inserting new records on that DataGrid, but I cannot find a way to do this. Is there a way to prevent a user from inserting a new row through the DataGrid. The data that gets entered into the datagrid is by using select statements.
Im using vb.net 2003.
Thanks
-
Mar 18th, 2007, 07:57 AM
#2
Fanatic Member
Re: Adding new records to a datagrid
Depending on what you want to do, u can set the 'readOnly' property of the dataGrid to true. Then u can't edit the grid at all even update the existing fields.
However u can use the click or double click event of the grid to update the fieldsd.
-
Mar 18th, 2007, 10:48 AM
#3
Thread Starter
Fanatic Member
Re: Adding new records to a datagrid
Thanks for your reply, what I am trying to do is basically show a datagrid with information, information can be edited and updated. I have this part all working but im having trouble as at the bottom of the datagrid the user can enter a new row with information but i dont want the user to be able to do this.
I have set the read only property of the datagrid to true and the user cant see the empty row at the bottom of teh data grid which is great, apart from the fact the user cannot edit the data now.
Any other suggestions please?
-
Mar 18th, 2007, 11:12 AM
#4
Fanatic Member
Re: Adding new records to a datagrid
The grid is either fully editable or not editable at all.
a work around will be to handle the updating of data in the click or dblClick event of the grid
1- user click on a row to select it
2- the information in the row are loaded inside some textboxes
3- the user modifies the textBoxes
4 - he validates the changes
5 - the selected row in the grid is updated
-
Mar 18th, 2007, 12:51 PM
#5
Thread Starter
Fanatic Member
Re: Adding new records to a datagrid
Thanks for your suggestion but i cannot use that method. I have no additional text boxes and the way you have suggested it, i cannot have it that way on my form.
Any other ideas please?
-
Mar 18th, 2007, 09:08 PM
#6
Thread Starter
Fanatic Member
Re: Adding new records to a datagrid
-
Mar 18th, 2007, 09:37 PM
#7
Re: Adding new records to a datagrid
If you bind a DataTable to a DataGrid and set the table's DefaultView.AllowNew property to False then the user will not be able to add new records. Note that you must assign the DataTable (or its DefaultView) to the grid's DataSource property. If you assign a DataSet to the DataSource property and then set the DataMember it will not work.
Note that the DefaultView property is type DataView, so if you want any more information you should look up that class. It also has AllowDelete and AllowEdit properties that do just what you'd expect.
-
Mar 20th, 2007, 02:23 PM
#8
Thread Starter
Fanatic Member
Re: Adding new records to a datagrid
Thanks alot buddy, that helped alot and ive solved the problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|