Thread: How Can Add Row In DataGrid - VBForums

  • Register
  • Help
  • Remember Me?
VBForums - Visual Basic and VB .NET Discussions and More!
  • Advanced Search
  • Home
  • VBForums
  • Visual Basic
  • Visual Basic 6 and Earlier
  • How can add row in DataGrid ?
Results 1 to 12 of 12 Thread: How can add row in DataGrid ? share-icon
  • Thread Tools
    • Show Printable Version
  • Display
    • Linear Mode
    • Switch to Hybrid Mode
    • Switch to Threaded Mode
  1. Dec 16th, 2008, 07:01 AM #1 memoon
    • View Profile
    • View Forum Posts
    memoon is offline

    Thread Starter Member Join Date Jul 2007 Posts 34

    Angry How can add row in DataGrid ?

    Hi How can add row in DataGrid ? Thanks
    Reply With Quote Reply With Quote
  2. Dec 16th, 2008, 07:18 AM #2 Hack
    • View Profile
    • View Forum Posts
    Hack is offline I'm about to be a PowerPoster! Hack's Avatar Join Date Aug 2001 Location Searching for mendhak Posts 58,333

    Re: How can add row in DataGrid ?

    Add a new record to your datasource.
    Reply With Quote Reply With Quote
  3. Dec 16th, 2008, 07:26 AM #3 memoon
    • View Profile
    • View Forum Posts
    memoon is offline

    Thread Starter Member Join Date Jul 2007 Posts 34

    Re: How can add row in DataGrid ?

    no i have 3 text in forn text1 , text2, text3 How can add row in DataGrid ? the data row from text do not save in databases only in form
    Reply With Quote Reply With Quote
  4. Dec 16th, 2008, 09:50 AM #4 Caskbill
    • View Profile
    • View Forum Posts
    Caskbill is offline Hyperactive Member Join Date Oct 2007 Location Indiana Posts 295

    Re: How can add row in DataGrid ?

    Why are you using a Datagrid? If your data is coming from text boxes, why not just use the MSFlexGrid control? To increase by one row in a Flesgrid the code would be... Code: MSFlexgrid1.rows = MSFlexgrid1.rows + 1
    Reply With Quote Reply With Quote
  5. Dec 16th, 2008, 12:08 PM #5 memoon
    • View Profile
    • View Forum Posts
    memoon is offline

    Thread Starter Member Join Date Jul 2007 Posts 34

    Re: How can add row in DataGrid ?

    hi i use datagrid not MSFlexgrid can i add row in DataGrid from text ? datagrid only not MSFlexgrid please help me
    Reply With Quote Reply With Quote
  6. Dec 17th, 2008, 06:34 AM #6 memoon
    • View Profile
    • View Forum Posts
    memoon is offline

    Thread Starter Member Join Date Jul 2007 Posts 34

    Re: How can add row in DataGrid ?

    can that or no ? please answer me
    Reply With Quote Reply With Quote
  7. Dec 17th, 2008, 07:21 AM #7 dee-u
    • View Profile
    • View Forum Posts
    • Visit Homepage
    dee-u is offline Software Carpenter dee-u's Avatar Join Date Feb 2005 Location Pinas Posts 11,123

    Re: How can add row in DataGrid ?

    The DataGrid is bound to a recordset, as such in order for it to Add new rows you will need to add records to your database which will be reflected in the DataGrid.
    Regards, ™ As a gesture of gratitude please consider rating helpful posts. c",) Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system
    Reply With Quote Reply With Quote
  8. Dec 17th, 2008, 01:11 PM #8 brucevde
    • View Profile
    • View Forum Posts
    brucevde is offline PowerPoster Join Date Oct 2002 Location British Columbia Posts 9,758

    Re: How can add row in DataGrid ?

    The DataGrid requires an OLEDB Datasource such as an ADO Recordset. As Hack & dee-u pointed out, to add a new row to the DataGrid simply add a record to it's underlying Recordset. You haven't indicated your requirements other than you don't want to use a database. Good news you don't need one. You can create and use an in-memory ADO Recordset. Add a Reference to the Microsoft ActiveX Data Object 2.X Library to your project. Code: Private Sub Form_Load() Dim rs As ADODB.Recordset 'Don't allow user to modify data in grid directly. With DataGrid1 .AllowAddNew = False .AllowDelete = False .AllowUpdate = False End With 'create an in-memory recordset with your required fields Set rs = New ADODB.Recordset rs.Fields.Append "LastName", adVarChar, 30 rs.Fields.Append "FirstName", adVarChar, 15 rs.Open 'bind recordset to Grid Set DataGrid1.DataSource = rs End Sub Private Sub cmdAdd_Click() Dim rs As ADODB.Recordset 'get the Grid's Recordset and add a new Record Set rs = DataGrid1.DataSource rs.AddNew Array("LastName", "FirstName"), Array(txtLastName.Text, txtFirstName.Text) 'you could use this syntax instead 'rs.AddNew 'rs.Fields("LastName").Value = txtLastName.text 'rs.Fields("FirstName").Value = txtFirstName.text 'ReBind the Grid so the new record is visible DataGrid1.ReBind End Sub Note that when the program is closed the data is lost. But it is simple enough to create a Save procedure to write the data to a text file or whatever your needs might be.
    Reply With Quote Reply With Quote
  9. Dec 19th, 2008, 10:28 PM #9 memoon
    • View Profile
    • View Forum Posts
    memoon is offline

    Thread Starter Member Join Date Jul 2007 Posts 34

    Re: How can add row in DataGrid ?

    thanks for soultion my Error
    Reply With Quote Reply With Quote
  10. Aug 5th, 2020, 08:08 AM #10 SaudVb
    • View Profile
    • View Forum Posts
    SaudVb is offline Junior Member Join Date Apr 2020 Posts 29

    Re: How can add row in DataGrid ?

    Quote Originally Posted by brucevde View Post The DataGrid requires an OLEDB Datasource such as an ADO Recordset. As Hack & dee-u pointed out, to add a new row to the DataGrid simply add a record to it's underlying Recordset. You haven't indicated your requirements other than you don't want to use a database. Good news you don't need one. You can create and use an in-memory ADO Recordset. Add a Reference to the Microsoft ActiveX Data Object 2.X Library to your project. Code: Private Sub Form_Load() Dim rs As ADODB.Recordset 'Don't allow user to modify data in grid directly. With DataGrid1 .AllowAddNew = False .AllowDelete = False .AllowUpdate = False End With 'create an in-memory recordset with your required fields Set rs = New ADODB.Recordset rs.Fields.Append "LastName", adVarChar, 30 rs.Fields.Append "FirstName", adVarChar, 15 rs.Open 'bind recordset to Grid Set DataGrid1.DataSource = rs End Sub Private Sub cmdAdd_Click() Dim rs As ADODB.Recordset 'get the Grid's Recordset and add a new Record Set rs = DataGrid1.DataSource rs.AddNew Array("LastName", "FirstName"), Array(txtLastName.Text, txtFirstName.Text) 'you could use this syntax instead 'rs.AddNew 'rs.Fields("LastName").Value = txtLastName.text 'rs.Fields("FirstName").Value = txtFirstName.text 'ReBind the Grid so the new record is visible DataGrid1.ReBind End Sub Note that when the program is closed the data is lost. But it is simple enough to create a Save procedure to write the data to a text file or whatever your needs might be. brucevde .. Yours is an example of a high-quality answer; most solutions on the internet are either half-mindedly put, too complicated, or are meant for off-showing purposes. Thank you very much; you solved my problem.
    Reply With Quote Reply With Quote
  11. Aug 6th, 2020, 05:58 PM #11 SaudVb
    • View Profile
    • View Forum Posts
    SaudVb is offline Junior Member Join Date Apr 2020 Posts 29

    Re: How can add row in DataGrid ?

    How to make it save data into the actual database instead of having it save into an in-memory recordset?
    Reply With Quote Reply With Quote
  12. Aug 7th, 2020, 06:44 PM #12 SaudVb
    • View Profile
    • View Forum Posts
    SaudVb is offline Junior Member Join Date Apr 2020 Posts 29

    Re: How can add row in DataGrid ?

    Since it is an in-memory recordset, is there a way to save its data for next program session?
    Reply With Quote Reply With Quote
Quick Navigation Visual Basic 6 and Earlier Top
  • Site Areas
  • Settings
  • Private Messages
  • Subscriptions
  • Who's Online
  • Search Forums
  • Forums Home
  • Forums
  • Visual Basic
    1. Visual Basic .NET
      1. CodeBank - VB.net
    2. Visual Basic 6 and Earlier
      1. CodeBank - Visual Basic 6 and earlier
    3. TwinBASIC
      1. CodeBank - TwinBASIC
    4. Universal Windows Platform and Modern Windows Experience
    5. Xamarin
    6. Mobile Development
    7. ASP, VB Script
    8. Office Development
    9. Database Development
    10. Reporting
    11. API
    12. Games and Graphics Programming
      1. Game Demos
    13. COM and ActiveX
    14. Network Programming
    15. Visual Basic FAQs
    16. Slow Chat with the Microsoft Visual Basic team
  • .NET and More
    1. ASP.NET And ASP.NET Core
    2. Visual Basic .NET
    3. MVC .Net
    4. C#
    5. Microsoft Azure and Cloud Dev
    6. WPF, WCF, WF
    7. .NET Architecture and Design
    8. Silverlight
  • General
    1. General Developer Forum
    2. IoT, IoE, and Maker Forum
    3. Testers and Testing
    4. Application Testing
    5. Application Deployment
    6. Linux Development
    7. General PC
    8. VBForums Coding Contests
      1. Contest Entries
    9. Code It Better
    10. Maths Forum
  • Other Languages
    1. Other BASIC
    2. C and C++
    3. Java
    4. PHP
    5. XML, HTML, Javascript, Web and CSS
    6. jQuery
    7. Assembly
    8. Other Programming Languages
  • VBForums CodeBank
    1. CodeBank - Visual Basic .NET
    2. CodeBank - Visual Basic 6 and earlier
    3. CodeBank - ASP / ASP.NET / Blazor / MVC / Web API
    4. CodeBank - C#
    5. CodeBank - C++
    6. CodeBank - Java / J#
    7. CodeBank - PHP
    8. Codebank - Game Programming
    9. Codebank - Mobile Development
    10. CodeBank - JavaScript
    11. Codebank - Cascading Style Sheets (CSS)
    12. CodeBank - Other
  • VBForums UtilityBank
    1. UtilityBank - Utilities
    2. UtilityBank - IDE Add-Ins
    3. UtilityBank - Components
    4. UtilityBank - Tutorials
    5. UtilityBank - Other
  • Projects
    1. Project Requests
    2. Project Communication Area
  • Jobs
    1. Just VB Jobs
    2. Open Positions (Jobs)
    3. Looking for Work
  • Community
    1. Forum Feedback
    2. General Discussion / Chit Chat
      1. World Events
    3. Forum Test Area
« Previous Thread | Next Thread »
  • Home
  • VBForums
  • Visual Basic
  • Visual Basic 6 and Earlier
  • How can add row in DataGrid ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML code is Off

Forum Rules

Click Here to Expand Forum to Full Width
Terms and Conditions | About Us | Privacy Notice | Contact Us | Advertise | Sitemap| California - Do Not Sell My Info

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.

All times are GMT -5. The time now is 06:50 AM.

Từ khóa » Visual Basic Datagridview Add Row