Results 1 to 8 of 8

Thread: [RESOLVED] [2008] datagridview single row

  1. #1

    Thread Starter
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Resolved [RESOLVED] [2008] datagridview single row

    hey guys
    how can i make the datagridview contains 1 row?
    because i have a toolbar that have two button(forward,backward) and i need the datagridview to be single row because each row is a record in The DB .
    and when i pree the forward button i will go to the next record.

    and btw, which is better this way or make the datagridview display all the records at once ????

  2. #2
    Member
    Join Date
    Feb 2009
    Location
    India
    Posts
    48

    Re: [2008] datagridview single row

    Its all according to your requirements. if you want all the records to be displayed then count the rows from the database table and display them or single row.

    You can add rows to datagridview this way.
    firstly put the datagridview's AllowUsertoAddRows and AllowUsertoDeleteRows property to False then add rows.
    vb Code:
    1. 'for single row
    2. datagridview.rows.add()
    3.  
    4. ' for multiple rows
    5. 'number is the number rows you want to add to datagridview
    6. datagridview.rows.add(number)
    Karun

    Dont forget to Rate my post,if you like it. Thank you.

  3. #3

    Thread Starter
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: [2008] datagridview single row

    ok but
    i mean i want the datagridview to display only one row (the first record in My DB).
    and when i press forward the same row in The Datagridview Will Be Changed the Information To the Second row In The DB.
    can i do that ?
    thx

  4. #4

    Thread Starter
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: [2008] datagridview single row

    where are you guys?

  5. #5
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: [2008] datagridview single row

    How are you loading the DGV, are you loading all the records from the table or are you calling the db for each record? How are you populating each cell of the DGV?

    Count the rows returned from the db and then catch the row number to assign each record. This is how I do it in a form with controls, but the principle is the same.

    Code:
    At form level declare these two variables
    ' declare a database cursor to point to the record 
    Dim dbCursor As Integer = 0
    ' declare a variable to hold the max number of records
    Dim MaxRecords As Integer
    
    ' Fill() is the method I use to populate a dataset, call yours whatever you want, remember do not just copy and past this into your form and expect it to work
    
    Private Sub btnFirstRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirstRecord.Click
        ' error checking
        Try
            dbCursor = 0
            Fill()
        Catch ex As Exception
            MsgBox("Error occurred in btnFirstRecord - Click event:" & ex.Message)
        End Try
    End Sub
    
    Private Sub btnPreviousRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviousRecord.Click
        ' error checking
        Try
           If dbCursor <> 0 Then
                dbCursor = dbCursor - 1
                Fill()
            End If
       Catch ex As Exception
            MsgBox("Error occurred in btnPreviousRecord - Click event:" & ex.Message)
        End Try
    End Sub
    
    Private Sub btnNextRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextRecord.Click
        ' error checking
        Try
            If dbCursor < MaxRecords - 1 Then
                dbCursor = dbCursor + 1
                Fill()
            End If
        Catch ex As Exception
            MsgBox("Error occurred in btnNextRecord - Click event:" & ex.Message)
        End Try
    End Sub
    
    Private Sub btnLastRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLastRecord.Click
        ' error checking
        Try
            dbCursor = MaxRecords - 1
            Fill()
        Catch ex As Exception
            MsgBox("Error occurred in btnLastRecord - Click event:" & ex.Message)
        End Try
        dbCursor = MaxRecords - 1
        Fill()
    End Sub
    Good luck
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  6. #6
    Member
    Join Date
    Feb 2009
    Location
    India
    Posts
    48

    Re: [2008] datagridview single row

    Quote Originally Posted by snakeman
    ok but
    i mean i want the datagridview to display only one row (the first record in My DB).
    and when i press forward the same row in The Datagridview Will Be Changed the Information To the Second row In The DB.
    can i do that ?
    thx

    yes,you can do that.
    clear all the columns of the datagridview and display the second row.

    'to clear all the columns in datagrid
    DataGridview.columns.clear()

    and then add the row to it and display your content.
    Karun

    Dont forget to Rate my post,if you like it. Thank you.

  7. #7
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2008] datagridview single row

    Normally the DataGridView should show all the records of your database not a single record. What is the purpose to show only one at the time? If that is what you want than you may consider using textboxes and binding them to the database fields so it will contain one record at the time. If you want to have DataGridView instead of textboxs than you need to add and remove the row manually witch will have no sense.

  8. #8

    Thread Starter
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: [RESOLVED] [2008] datagridview single row

    thx every one

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