Results 1 to 3 of 3

Thread: [RESOLVED] Manually adding data to DataGridView

  1. #1

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Resolved [RESOLVED] Manually adding data to DataGridView

    I'm using DataGridView without binding it to any source. I want to add all data manually.

    I got the way to add a new row.
    Code:
    empDataGridView.Rows.Add()   'empDataGridView is the name of DataGridView
    But, how can I add a piece of data to particular cell of the particular row? And retrieve the Index of row when a row is clicked.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Manually adding data to DataGridView

    The row has an Index property that gives you the index of that row in the grid's Rows collection.

    If you want to add data to an existing row then you need to index the row's Cells collection to access a particular cell and then set its Value property. If you have all the data before adding then it would be easier to call the overload of Add that has a single Object array parameter. That allows you to pass the cell values and have them added to the cells when the row is created. That parameter is a ParamArray, so you can pass a single Object array or you can pass the discrete values as separate arguments.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Manually adding data to DataGridView

    Okay. That wasn't hard actually.

    Code:
    DataGridView.Rows(index).Cells(index).value
    Thanks.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width