Hi,
I'm getting the error system.indexoutofrangeexception when trying to filter a datagridview's datasource(dataview).
This is the code I use to fill the Datagridview
I then use this to filter it
The datagridview loads fine and the filter works until I try to search for something that isn't there.
I don't understand why it does this though as doing this on another dataview works fine and just brings up a blank datagrid.
Anyone have any idea?
Kind Regards
Philip Smith
I'm getting the error system.indexoutofrangeexception when trying to filter a datagridview's datasource(dataview).
This is the code I use to fill the Datagridview
VB.NET:
FileDav = New DataView
Try
With FileDav
.Table = ds.Tables("dboFile")
.AllowDelete = False
.AllowEdit = True
.AllowNew = False
.RowFilter = "IsActive = 1"
.RowStateFilter = DataViewRowState.CurrentRows
.Sort = "ShortFileName"
End With
DataGridView1.Columns.Clear()
DataGridView1.DataBindings.Clear()
With DataGridView1
.AutoGenerateColumns = False
.Columns.Insert(0, New DataGridViewTextBoxColumn)
.Columns(0).Name = "ShortFileName"
.Columns(0).HeaderText = "Short File Name"
.Columns(0).DataPropertyName = "ShortFileName"
.Columns(0).ReadOnly = True
.Columns.Insert(1, New DataGridViewTextBoxColumn)
.Columns(1).Name = "MatterIdString"
.Columns(1).HeaderText = "Matter ID"
.Columns(1).DataPropertyName = "MatterIDString"
.Columns(1).ReadOnly = True
.Columns.Insert(2, New DataGridViewCheckBoxColumn)
.Columns(2).Name = "IsActive"
.Columns(2).HeaderText = "Active / Closed"
.Columns(2).DataPropertyName = "IsActive"
.Columns(2).ReadOnly = True
.Columns.Insert(3, New DataGridViewCheckBoxColumn)
.Columns(3).Name = "IsSelected"
.Columns(3).DataPropertyName = "IsSelected"
.Columns(3).HeaderText = "Is Selected?"
.Columns(3).ReadOnly = False
.Columns.Insert(4, New DataGridViewTextBoxColumn)
.Columns(4).Name = "ID"
.Columns(4).HeaderText = "ID"
.Columns(4).DataPropertyName = "Id"
.Columns(4).ReadOnly = True
.Columns(4).Visible = False
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.RowHeadersVisible = False
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToOrderColumns = False
.AllowUserToResizeColumns = False
.AllowUserToResizeRows = False
.DataSource = FileDav
End With
Catch ex As Exception
SendErrorByMailMessage(ex.Message)
End Try
I then use this to filter it
VB.NET:
' MatterIdString <> ''"""
Dim Search As String
Search = SearchTextBox.Text.Replace("'", "''")
SearchString = "MatterIdString <> ''"
If ComboBox1.SelectedValue = 0 Then
Else
SearchString = SearchString & " AND FileTypeId = " & ComboBox1.SelectedValue
End If
If ShowClosed = True Then
Else
SearchString = SearchString & " AND IsActive = 1"
End If
If SearchTextBox.Text = "" Then
Else
SearchString = SearchString & " AND (ShortFileName LIKE '%" & Search & "%' OR MatterIDString LIKE '%" & Search & "%')"
End If
If ComboBox2.SelectedValue = 0 Then
Else
SearchString = SearchString & " AND FileStatusID = " & ComboBox2.SelectedValue
End If
SearchString = SearchString
Try
FileDav.RowFilter = SearchString
Catch ex As Exception
MsgBox(ex.Message)
End Try
The datagridview loads fine and the filter works until I try to search for something that isn't there.
I don't understand why it does this though as doing this on another dataview works fine and just brings up a blank datagrid.
Anyone have any idea?
Kind Regards
Philip Smith