Adding New Row In Datagridview [SOLVED] - - Daniweb
Có thể bạn quan tâm
- Home
- Programming Forum
- Software Development Forum
- Discussion / Question
I'm doing a system in VB.net 2012 where a user inputs a data on a textbox and then if the user clicks on the button, the data in the textbox will show on the datagridview. The problem I'm having is when I input another data, the current data shown in the datagridview is replaced instead of having a new row for the inputted data. This is the code I've worked on:
Private Sub btn_addborrow_Click(sender As Object, e As EventArgs) Handles btn_addborrow.Click Dim dt As New DataTable Dim dsNewRow As DataRow = dt.NewRow() With dgv_booklist dt.Columns.Add("ISBN", GetType(String)) dt.Columns.Add("BookCode", GetType(String)) dt.Columns.Add("Title", GetType(String)) dt.Columns.Add("Author", GetType(String)) dt.Columns.Add("Category", GetType(String)) dt.Columns.Add("StudentNo", GetType(String)) dt.Columns.Add("FirstName", GetType(String)) dt.Columns.Add("LastName", GetType(String)) dt.Columns.Add("BorrowDate", GetType(String)) dt.Columns.Add("LoanPeriod", GetType(String)) dsNewRow.Item("ISBN") = txtbox_isbn.Text dsNewRow.Item("BookCode") = txtbox_code.Text dsNewRow.Item("Title") = txtbox_title.Text dsNewRow.Item("Category") = txtbox_category.Text dsNewRow.Item("StudentNo") = txtbox_studno.Text dsNewRow.Item("FirstName") = txtbox_firstname.Text dsNewRow.Item("LastName") = txtbox_lastname.Text dsNewRow.Item("BorrowDate") = dtp_borrowdate.Text dsNewRow.Item("LoanPeriod") = txtbox_loanperiod.Text dgv_booklist.DataSource = dt dt.Rows.Add(New Object() {txtbox_isbn.Text, txtbox_code.Text, txtbox_title.Text, txtbox_author.Text, txtbox_category.Text, txtbox_studno.Text, txtbox_firstname.Text, txtbox_lastname.Text, dtp_borrowdate.Text, txtbox_loanperiod.Text}) End With End SubI've searched and searched but I really can't add a new row on my datagridview. If you could point out what I did wrong in the code and what I could do to change the mistake, that would be much appreciated.
vb.net 0 0 Share- 2 Contributors
- 2 Replies
- 15K Views
- 9 Hours Discussion Span
- Latest Post 10 Years Ago Latest Post by Mae_1
wow buddy your code doesn't make any sense. you should run this once
With dgv_booklist .Columns.Add("ISBN", "ISBN") .Columns.Add("BookCode", "BookCode") .Columns.Add("Title", "Title") .Columns.Add("Author", "Author") .Columns.Add("Category", "Category") .Columns.Add("StudentNo", "StudentNo") .Columns.Add("FirstName", "FirstName") .Columns.Add("LastName", "LastName") .Columns.Add("BorrowDate", "BorrowDate") .Columns.Add("LoanPeriod", "LoanPeriod") End Withand that's the add row code
Private Sub btn_addborrow_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_addborrow.Click dgv_booklist.Rows.Add(txtbox_isbn.Text, txtbox_code.Text, txtbox_title.Text, txtbox_author.Text, txtbox_category.Text, txtbox_studno.Text, txtbox_firstname.Text, txtbox_lastname.Text, dtp_borrowdate.Text, txtbox_loanperiod.Text) End Sub 1 0 ShareI followed your code and it works now. Thank you!
0 0 Share Share Facebook Twitter LinkedIn Reply to this topic Be a part of the DaniWeb communityWe're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.
Sign Up — It's Free! Related Topics- vb.net code to insert data on datagridview to access database 3
- Vb.net Projects 11
- Checkbox in the Title Bar 2
- VB.NET ERROR "parameter is not valid" 5
- A 21320115 DUT 2
- Vb.net 4
- accessing database 1
- vb.net help for date 6
- link 'drag/drop GUI' to 'C++ Code' 15
- vb.net invokescript to call ajax function 1
- Disabling and enabling ctrl keys 14
- Vb.Net - Database Password Save 5
- code for login forum in c# 2
- Vb.net with SQL 3
- Account Program 0
- Vb.net Sample Project 16
- Overloading a function 8
- VB.NET Tally radio button and save the answer in sql database 8
- Vb.net and Jemter Testing 4
- VB.Net with External File 5
Reach out to all the awesome people in our software development community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions.
Start New Topic Topics Feed Reply to this Topic Edit Preview Message H1 H2 Post ReplyShare Post
Permanent Link Facebook Facebook Twitter Twitter LinkedIn LinkedInInsert Code Block
Insert Code Block Search Search- Forum Categories
- Latest Content
- Newest Topics
- Latest Topics
- Latest Posts
- Latest Comments
- Top Tags
- Topics Feed
- Social
- Forums
- Top Members
- Meet People
- Community Functions
- DaniWeb Premium
- Newsletter Archive
- Markdown Syntax
- Community Rules
- Developer APIs
- Connect API
- Forum API Docs
- Tools
- SEO Backlink Checker
- Legal
- Terms of Service
- Privacy Policy
- FAQ
- About Us
- Advertise
- Contact Us
Từ khóa » Visual Basic Datagridview Insert Row
-
Add Row To Datagridview Programmatically Code Example
-
DataGridView Adding Rows And Columns In VB.NET
-
How Do I Add Records To A DataGridView In VB.Net? - Stack Overflow
-
How To Add A Row To DataGridView From TextBox In VB.NET ...
-
VB.NET Tutorial 34 : DataGridView Example (Adding Row) In Visual ...
-
Datagridview Add Rows - YouTube
-
Add Rows In To Bounded Datagridview - MSDN - Microsoft
-
DataGridViewRowCollection.Insert Method (System.Windows.Forms)
-
Programmatically Add New Rows To An Unbound DataGridView ...
-
[Solved] Datagridview Add Empty Rows ? - CodeProject
-
How To Add Row To DataGridView In Visual Basic (Visual Studio)
-
How To Add A Row To DataGridView From TextBox In VB.NET
-
Prevent (Disable) Adding New Row To DataGridView In Windows ...
-
Adding And Inserting Rows - WinForms GridView Control