|
-
May 3rd, 2007, 06:59 AM
#1
Thread Starter
Lively Member
[2005] Using a filter on BindingSource with BindingList
Hi there,
I've been messing with the DataGridView component and it's really quite cool what you can do with it. I have it working for the most part, apart from one thing. I can't seem to get filtering working. The code I have is fort testing purposes only, basically just to get to know how to work with the DGV. I did notice that bSource.SupportsFiltering was set to False and I have no idea how to change that.
vb Code:
Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim bList As New System.ComponentModel.BindingList(Of ListItem)
Dim bSource As New BindingSource()
bSource.DataSource = bList
' ListItem has Name, ID and Important properties, which are String, Integer and Boolean
' respectively.
bList.Add(New ListItem("Item 1", 1, True))
bList.Add(New ListItem("Item 2", 2, False))
bList.Add(New ListItem("Item 3", 3, True))
bList.Add(New ListItem("Item 4", 4, False))
DataGridView1.DataSource = bSource
DataGridView1.ColumnHeadersVisible = False
' This makes sure that only 'Important' and 'Name' are shown and displayed
' in the correct order
DataGridView1.Columns(2).DisplayIndex = 0
DataGridView1.Columns(1).DisplayIndex = 1
DataGridView1.Columns(0).DisplayIndex = 2
DataGridView1.Columns(0).Visible = False
DataGridView1.Columns(2).Width = 20
DataGridView1.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
DataGridView1.GridColor = Color.White
DataGridView1.RowHeadersVisible = False
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bSource As BindingSource = DataGridView1.DataSource
bSource.Filter = "ID == 2"
DataGridView1.Refresh()
End Sub
Basically, to test the filter, I wanted to press a button and then apply the filter. I am sure that once I get the hang of the filtering, I can implement it fully in my main app.
Gr,
Mightor
What the world needs is more geniuses with humility, there are so few of us left.
If my post was accidentally useful, please rate it as such, thanks!
Mon aéroglisseur est plein des anguilles.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|