Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to implement Add Edit Select in DataGridView1 in VB.NEt Windows Form.

Posted on 2012-04-09
11
Medium Priority
?
246 Views
Last Modified: 2012-04-14
How to implement Add Edit Select in DataGridView1 in VB.NEt Windows Form.I want to put Add Edit Button.
0
Comment
Question by:searchsanjaysharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 5

Assisted Solution

by:rtay
rtay earned 1712 total points
ID: 37826407
Visual basic will add it for you automatically.  Drag the gridview onto the form, add a dataset making sure your table has a primary key.  At the end of the wizard for the dataset, click the checkbox to enable editing.  After wizard is complete, click the tag on the upper right corner of the gridview and check the boxes for add delete button and other options
0
 

Author Comment

by:searchsanjaysharma
ID: 37826481
I think you need to under the question properly, when i say Add Edit, it also means functionality at backend.
0
 
LVL 5

Assisted Solution

by:rtay
rtay earned 1712 total points
ID: 37827378
Please explain.  What function at backend?  Maybe a little more explanation of what you are trying to do will help me understand better.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:searchsanjaysharma
ID: 37827666
See if i bind data to datagridview and click on any cell and edit it it does not get reflected to database.
Thats what i mean to achive,
0
 
LVL 5

Assisted Solution

by:rtay
rtay earned 1712 total points
ID: 37827791
What database are you using?  SQL?  Attach a text copy of the table you are trying to use.
0
 
LVL 5

Assisted Solution

by:rtay
rtay earned 1712 total points
ID: 37827799
Also, when you create your dataset, are you having any difficulty attaching to the database?  Are you permissions ok?
0
 

Author Comment

by:searchsanjaysharma
ID: 37828777
No dear,
you assume, table name as emp, DataGridview1 is the datagrid.
emp contains three fields.
empno empname and city.
When i double click any cell it can be edited. Now i want to save it on button click
0
 
LVL 5

Assisted Solution

by:rtay
rtay earned 1712 total points
ID: 37828847
Private Sub Tbl_NameBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbl_NameBindingNavigatorSaveItem.Click
        Try
            Me.Validate()
            Me.Tbl_NameBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.DataSetName)

above code goes into your button_Click event.  My code is attached to the saveitem event that is automatically generated when creating a gridview in Visual Studio.  I create a dataset first, then just drag the dataset onto the form  The gridview automatically puts the save item and navigation across the top.  If you just want a save button you can add a button controll to your gridview and add the code above to it on the Button_Click event.  

Gridview will not generate the navigation tool bar with save button if your table does not have a primary key assigned to an ID field.  The field needs to be able to autogenerate a new number if you are going to add records.  I would add another field to your table as an ID Field with auto incrementing selected.
0
 
LVL 5

Assisted Solution

by:rtay
rtay earned 1712 total points
ID: 37828865
Sorry, leave the "Try" out of the above code.  That is the start of the code that validates the database before items are saved, i deleted the other out, but forgot that.  And add the end sub to the bottom of that.
0
 
LVL 10

Accepted Solution

by:
adriankohws earned 288 total points
ID: 37843780
I would suggest not to use the built-in buttons, you can easily allow user to edit any cell so long it's not Read Only attribute, you can detect any changes upon:

User leaving the row or leaving the cell, both of them will execute events that can be found in datagridviews. Then you can update your dataset, if you are using binding, otherwise, you can capture the row data and execute SQL statement for updating.
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37846028
ok
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question