none
Visual Basic 2008 : How to Add and Delete DataGridView Rows Using a Button that Scrolls Down/Up with the Grid?

    Question

  • To Remove
    http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/a6da7c09-cc60-448e-9f86-41f5ff804c20/


    To Add: I used this code

    Private

     

    Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

     

    ProductsDataGridView.AllowUserToAddRows =

    True ' This will display a new row at the bottom of the grid

    ProductsBindingSource.Position = ProductsDataGridView.Rows(ProductsDataGridView.Rows.Count - 1).Index

    ProductsDataGridView.Focus()

    SendKeys.Send(

    "{DOWN}") ' This will simulate a Arrow Down as though you press your arrow down key

     

     

     

     

    End Sub

    How do I add the button that scrolls down / up as I add or delete rows on the grid?


    FPENA
    Sunday, December 27, 2009 5:47 AM

Answers

  • This is a good tutorial; step by step

    http://dotnetperls.com/datagridview-vbnet


    === Program that adds rows (VB.NET) ===

    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' Add row using the Add subroutine.
            Dim n As Integer = DataGridView1.Rows.Add()
            DataGridView1.Rows.Item(n).Cells(0).Value = "First"
            DataGridView1.Rows.Item(n).Cells(1).Value = "Second"
        End Sub
    End Class

    FPENA
    Sunday, December 27, 2009 8:47 PM

All replies

  • FPena,

    A new row will added at the bottom of a datagridview which has not set sort at the bottom as soon as you add a row to its datasource.

    It depends for that if you use:
    a DataTable or a List or a BindingSource or a DataView (defaultview of a datatable)

    However they all have the possibility to add a new empty row.

    So create a button and add a row to that datasource.

    Code you can have the luck that somebody shows here one of the 1000 posibilites, but a little bit showing a lack of knowledge as that is done as long as you did not show how and with what you have popultated your datagridview


    Success
    Cor
    Sunday, December 27, 2009 6:49 AM
  • This is a good tutorial; step by step

    http://dotnetperls.com/datagridview-vbnet


    === Program that adds rows (VB.NET) ===

    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' Add row using the Add subroutine.
            Dim n As Integer = DataGridView1.Rows.Add()
            DataGridView1.Rows.Item(n).Cells(0).Value = "First"
            DataGridView1.Rows.Item(n).Cells(1).Value = "Second"
        End Sub
    End Class

    FPENA
    Sunday, December 27, 2009 8:47 PM