Results 1 to 9 of 9

Thread: [2008] Getting SelectedIndex of ListView For DataRow When . . .

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    [2008] Getting SelectedIndex of ListView For DataRow When . . .

    Alright. I have a List View:

    and 3 Buttons

    First Button : ALL
    Second Button : Incomplete
    Third Button : Complete

    Now I have a Access Database that has Data In it, and a Column called Completed.

    The Rows Either have True or False for that Column.

    Now when I click Incomplete only the Rows with False in it will show, and vice versa for Complete.

    This all works. But now I run into a Problem.

    Here is some Test Data for my Problem:

    Code:
    1         False         09/09/09
    2         False         09/08/08
    3         True          09/07/07

    So now those will show in ALL, but When I click COmplete, only "3" will show, but when I go to click on it, and Click Edit to Fill my Text Boxes with the Data, It gets the Data from the Selected Index ("0") which would get data for "1".

    So here is my Code to Get the Index & Load to Text Boxes, I don't know how to get the Selected Item to load for that piece of Item.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Getting SelectedIndex of ListView For DataRow When . . .

    can you post your code?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Getting SelectedIndex of ListView For DataRow When . . .

    lol, omg, I'm sorry :P

    Code:
        Public Sub LoadToTextBoxes()
            With frmAssignments
                Adapter.SelectCommand = New OleDbCommand("SELECT * FROM [Assignments]")
                Adapter.SelectCommand.Connection = Connection
                DS = New DataSet()
                Adapter.Fill(DS)
                Dim DRow As DataRow
                Dim selNdx As Integer = .lstAssign.SelectedIndices(0)
                DRow = DS.Tables(0).Rows(selNdx)
                .txtAssignments.Text = DRow.Item("Assignment").ToString
                .dtpDueDate.Value = Date.Parse(DRow.Item("DueDate").ToString)
                .cbCompleted.Checked = CBool(DRow.Item("Completed").ToString)
                '.cmbSubject.SelectedItem = DRow.Item("Subject").ToString
                .txtGrade.Text = DRow.Item("Weight").ToString
                .txtDesc.Text = DRow.Item("Description").ToString
            End With
        End Sub

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Getting SelectedIndex of ListView For DataRow When . . .

    is your listview multiselect property set to true?

    do you want the index of the last selecteditem?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Getting SelectedIndex of ListView For DataRow When . . .

    ListView is not Multiselect, its Full Row Select, and only gets the Index of the Selected Row

    And I want the Index of the Item I choose, so say I go into Complete and the First 2 Items are Incomplete then in my Database the CIndex (CIndex is a AutoIncrement # that gets Created with Each Item) would be

    1
    2
    3 < This one I want

    but when I go to Complete in the ListView, the Index is 0.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Getting SelectedIndex of ListView For DataRow When . . .

    i don't understand. you want it to return the selectedindex?

    or you want it to loop through the listviewitems + find the 1st 1 thats complete?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Getting SelectedIndex of ListView For DataRow When . . .

    Ok, see I don't know what I need to find. What I want to do is.


    Code:
    NAME | COMPLETED | DATE
    1         False         09/09/09
    2         False         09/08/08
    3         True          09/07/07
    Their is my Test Data.

    Now I have 3 Views in the ListView (Completed, Incomplete'd, and All)


    So What I'm trying to do is, find a Way when I completed or Incompleted Clicked, that I can get the Proper Index or Something, to match up according to What Button I pressed.
    All will show what is above.

    Completed would only show
    3 True 09/07/07
    Incomplete would only show
    1 False 09/09/09
    2 False 09/08/08

    But the CIndex of the Data is 1, 2, 3. (CIndex is the AutoIncrement # I get for a Unique Piece of Data).

    So, when I click the Complete Tabl, only "3" will show: And when I click it, and press EDIT, it will fill the TextBoxes with Incomplete "1" because that's the Index in the ListView that Corresponds to the CIndex in the Database File.

    Makes anymore Sense?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Getting SelectedIndex of ListView For DataRow When . . .

    Anyone? Still having trouble with this issue.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Getting SelectedIndex of ListView For DataRow When . . .

    I haven't read this thread in detail but it seems to me that the ListView is the wrong control for this. If you are only using Details View and you aren't using the grouping functionality then why use a ListView instead of a DataGridView? With a DGV you simply bind your DataTable to a BindingSource and bind that to the grid. Filtering is simply a matter of setting the Filter property of the BindingSource. It's two lines of code to bind the data in the first place and one line to filter each time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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