Checkbox delete issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Checkbox delete issue

  1. #1
    Join Date
    Jan 2010
    Posts
    17

    Post Checkbox delete issue

    Hey everyone, I'm having a little problem with my VB code. The program I am using is apart of a college project i have to create. Basically the search function within this program finds a person e.g. "Kari" and when the checkbox is clicked it should remove that person. However, the code for the checkbox is deleting the first record everytime and not the record selected, I was woundering if anyone could help me with the code?

    Private Sub Check1_Click()
    lst_name.ListIndex = 0
    lst_surname.ListIndex = lst_name.ListIndex
    lst_Pck_Point.ListIndex = lst_name.ListIndex
    lst_Dest_Point.ListIndex = lst_name.ListIndex
    lst_Times.ListIndex = lst_name.ListIndex
    lst_name.RemoveItem lst_name.ListIndex
    lst_surname.RemoveItem lst_surname.ListIndex
    lst_Pck_Point.RemoveItem lst_Pck_Point.ListIndex
    lst_Dest_Point.RemoveItem lst_Dest_Point.ListIndex
    lst_Times.RemoveItem lst_Times.ListIndex
    Check1.Value = 0
    Check1.SetFocus
    Check1.Value = 0
    End Sub

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,984

    Re: Checkbox delete issue

    This statement tells it to use the first record.
    Code:
    lst_name.ListIndex = 0
    Just DIM it first:

    Code:
    Dim LI As Integer
    LI= lst_name.ListIndex
    and use LI for the right value
    Last edited by dglienna; January 20th, 2010 at 03:46 PM.
    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
    Jan 2010
    Posts
    17

    Re: Checkbox delete issue

    do you mean something like that?

    Dim ListIndex As Integer
    ListIndex = lst_name.ListIndex

    By the way i'm a noob so i'm not too sure on this

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,984

    Re: Checkbox delete issue

    That's a reserved word, so, no you can't. That's why I used LI instead.

    Actually ListIndex = 0 should be a hint, but I'll tell you. Always use .ListIndex - 1, and check for -1 instead of 0
    Last edited by dglienna; January 20th, 2010 at 10:07 PM.
    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!

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center