Hi, after problems with using checkedlistboxes and the rest. I decided to take an easier route and use a listbox which i have populated from a database. It contains text with values assigned to it. i also have a DGV with 4 columns. The column i wish to sort by contains integers only.

I am just wondering how i can sort the DGV by passing a value from the listbox.. here is my code:

Private Sub lstCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstCat.SelectedIndexChanged
        'MsgBox("you selected " + lstCat.SelectedValue.ToString)
        Dim i As Integer

        i = lstCat.SelectedValue

        'DGVShops.Sort(DGVShops.Columns(1), System.ComponentModel.ListSortDirection.Ascending)
    End Sub

The msgbox was for testing the values are correct.
i is supposed to equal the value of selected index (which is fortunately the same as the CatID will be i want to sort by)

The last line just sorts it in ascending, but i would like to sort the column by whatever given value (2,3,4, etc)

8 Years
Discussion Span
Last Post by Fritzeh

I am also having problems trying to use a textbox to search for a value in the name column.

1. User types "String" into txtbox
2. press ok
3."String" passed to DGV/dataset/bindingsource/what?
4. Datagridview displays reults with "string" in the set column. only.

My main problem is i dont know how to pass the data to, whatever im passing it to. the above problem is similar surely, just using an integer instead of a string.

please help!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.