Results 1 to 13 of 13

Thread: Datagrid row delete

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Datagrid row delete

    Hello guys,

    I want to delete a particular row which is selected in the datagrid(ie datagrid.text row will be delete)....

    How to do? Advance thanks

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Datagrid row delete

    Try this:
    Code:
    Private Sub Command4_Click()
        If MsgBox("Are you sure", vbQuestion + vbYesNo, "Confirm Delete") = vbYes Then
            Adodc1.Recordset.Delete adAffectCurrent
            Adodc1.Recordset.Requery
            Adodc1.Refresh
            DataGrid1.Refresh
        End If
    End Sub

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datagrid row delete

    In other words, don't delete the record from the grid. Delete it from the underlaying datasource, i.e., your database, and then refresh the grid.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Datagrid row delete

    Quote Originally Posted by Hack
    In other words, don't delete the record from the grid. Delete it from the underlaying datasource, i.e., your database, and then refresh the grid.
    ... or better yet don't use any databound controls at all and no data control either.

    MsFlexgrid and ADO library can be much more better choice.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Re: Datagrid row delete

    First Thanks for your reply guys...

    Still i didn't get...

    I am using the ADODB.connection for recordset ie. Dim r As ADODB.Recordset

    for adding i am using r.fields("File name")=string

    I am using the datagrid for display the recordset... Now i want to delete the "datagrid1.text" row completly..... What to do :confused?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datagrid row delete

    Quote Originally Posted by kpmsivachand
    What to do :confused?
    This
    Quote Originally Posted by RhinoBull
    MsFlexgrid and ADO library can be much more better choice.
    Or, I'm a fan of the Listview.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Re: Datagrid row delete

    Quote Originally Posted by Hack
    ThisOr, I'm a fan of the Listview.
    I cann't get u?

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datagrid row delete

    As RhinoBull suggested, don't use the DataGrid. It is a bound control which by its very nature, is limiting in how it can be manipulated.

    Switch to a FlexGrid (his control of choice) or a ListView (my control of choice) and load the control of your choice from a recordset that you create based on an SQL query.

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Datagrid row delete

    Your Datagird is BOUND to a Recordset object - you cannot just delete line from the grid without actually deleting it first from the underlying recordset.
    If you are not using data control then get rid of Adodc1 in my sample.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Re: Datagrid row delete

    Quote Originally Posted by Hack
    Switch to a FlexGrid (his control of choice) or a ListView (my control of choice)
    Ok i will try using the flexgrid.... But in the listview, can we make the mulitiple coloumns in a single row?

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datagrid row delete

    Quote Originally Posted by kpmsivachand
    But in the listview, can we make the mulitiple coloumns in a single row?
    You betcha

  12. #12
    Addicted Member
    Join Date
    Oct 2006
    Location
    Chennai, India
    Posts
    198

    Re: Datagrid row delete

    Hack, is that everything we do with FlexGrid or most of the feature of FlexGrid is handled using ListView? If possible can you suggest me a sample please.. I am in eager to use the alternative controls for list of Information. Thanks....
    Regards
    Srinivasan Baskaran
    India

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datagrid row delete

    I haven't used a FlexGrid is so long, I'm can't remember exactly what it does do. However, if you are interested in exploring either the FlexGrid or the ListView, then I would ask that you create your own thread for this topic.

    Thanks.

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