CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    70

    Datagridview not editing

    HI
    IN MY VB.NET 2005 APPLICATION, I placed one datagridview conntrol.
    This control is filled from from a table(single table involved) using datatable and dataadapter.

    I want to edit the the data in the grid and and pass changes to the table direclty.
    user can change data in the gird but not get reflected the changes in the database.

    I even tried even MSDN sample code for filling the datagridview, but still not working

    any idea
    VB.Net 2005, Net Framework 2.0

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Datagridview not editing

    Post the error, and code of what you've tried. It's easier to bind controls than not, but you can also NOT update a record. It depends on what you've done so far...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2008
    Posts
    70

    Re: Datagridview not editing

    using the following code I initialise my grid
    gird is filled, I want user to edit the columns, could add new rows, delete exisiting one.
    Grid is editable, but not reflected into the database


    Dim dt1 As New DataTable, adptr1 As New SqlDataAdapter ' declared at class objects
    Private Sub InitializeDataGridView()

    Try
    ' Set up the DataGridView.
    With Me.DataGridView2
    ' Automatically generate the DataGridView columns.
    .AutoGenerateColumns = True


    cmdobj.CommandType = CommandType.Text
    cmdobj.CommandText = "select * fromauthors"
    adptr1.SelectCommand = cmdobj : adptr1.Fill(dt1)

    BindingSource1.DataSource = dt1
    DataGridView2.DataSource = BindingSource1 '.Tab

    ' Automatically resize the visible rows.
    .AutoSizeRowsMode = _
    DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders

    ' Set the DataGridView control's border.
    .BorderStyle = BorderStyle.Fixed3D

    ' Put the cells in edit mode when user enters them.
    .EditMode = DataGridViewEditMode.EditOnEnter
    End With
    Catch ex As SqlException
    MessageBox.Show(ex.Tomessage)
    System.Threading.Thread.CurrentThread.Abort()
    End Try
    End Sub
    VB.Net 2005, Net Framework 2.0

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Datagridview not editing

    This should do it:
    Code:
    DataGridView2.DataSource = String.Empty
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Aug 2008
    Posts
    70

    Re: Datagridview not editing

    Dear lienna

    where to set this property?, string.empty

    kindly give me a tutorial, the mechanism of editing and reflecting to
    underlying tables of datagridview
    VB.Net 2005, Net Framework 2.0

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

Featured