Less Ugly Way to Filter Data Into a Collection?

P

Patrick A

I have a form where buttons are added by code. I want to filter the
buttons on the "Show" column in my data source unless the user has
indicated otherwise, which sets MyGlobals.ShowAllButtons = True.

The code below works, but I can't believe there is not a better way.
I have tried to filter the Binding Source a variety of ways,
Me.QRY_ButtonsBindingSource.Filter = "Show = True"
Me.QRY_ButtonsBindingSource.Filter = "Show = 'True'"
Me.QRY_ButtonsBindingSource.Filter = "Show =" & True
Me.QRY_ButtonsBindingSource.Filter = "Show =" & "'True'"
but with no results.

Am I totally misunderstanding the concept of "where and how" to
filter, or is there an easier way?

Thanks,

Patrick


Me.QRY_ButtonsTableAdapter.ClearBeforeFill = True

Me.QRY_ButtonsTableAdapter.Fill(Me.L55TimerDataSet.QRY_Buttons)

Dim Row As Integer = 0

Dim ButRecds =
L55TimerDataSet.Tables("QRY_Buttons").AsEnumerable '.Select("Show =
True")

Dim sortedButRecds = From a_row In ButRecds Select a_row

'Get values - labels, meanings, colors, etc. from the DB.
For Each a_row In sortedButRecds 'Iterate through the
collection.
If MyGlobals.ShowAllButtons = False Then
If a_row!show = True Then
Row = Row + 1 'Increment up.
NewButton = New MyButton(Me) ' Sets a new
button
Me.Panel1.Controls.Add(NewButton) 'Adds the
new button to the form.
NewButton.butID = a_row!TimerID.ToString
NewButton.Name = (a_row!Position) 'Pull the
TimerPos from DS and use it as a tag.
NewButton.Text = (a_row!Label) 'Pull the
butLabel from DS and use it as text.
NewButton.butLabel = a_row!Label.ToString '
NewButton.butNarr = a_row!Narrative.ToString
'Read the Work Description from the DB.
NewButton.butDispCM = a_row!
ClientMatter.ToString 'Read the Cli/Mat from the DB.
NewButton.butTask = a_row!Task.ToString 'Read
the Task Code from the DB.
NewButton.butAct = a_row!Activity.ToString
'Read the Activity Code from the DB.
NewButton.butDisplaySpan =
TimeSpan.FromSeconds(a_row!daySpan)
NewButton.butLoc = MyGlobals.CurrentLoc
NewButton.BackColor = Color.FromName(a_row!
Color) 'Read the color of the button
NewButton.butShowMe = a_row!show ' Read the
Show or Don't Show value for the button
' Set up the Right-Click menu
NewButton.ContextMenuStrip = cmTimeButs
oTimeSliceCollection.Add(NewButton,
a_row("TimerID").ToString)
End If
Else
Row = Row + 1 'Increment up.
NewButton = New MyButton(Me) ' Sets a new button
Me.Panel1.Controls.Add(NewButton) 'Adds the new
button to the form.
NewButton.butID = a_row!TimerID.ToString
NewButton.Name = (a_row!Position) 'Pull the
TimerPos from DS and use it as a tag.
NewButton.Text = (a_row!Label) 'Pull the butLabel
from DS and use it as text.
NewButton.butLabel = a_row!Label.ToString '
NewButton.butNarr = a_row!Narrative.ToString 'Read
the Work Description from the DB.
NewButton.butDispCM = a_row!ClientMatter.ToString
'Read the Cli/Mat from the DB.
NewButton.butTask = a_row!Task.ToString 'Read the
Task Code from the DB.
NewButton.butAct = a_row!Activity.ToString 'Read
the Activity Code from the DB.
NewButton.butDisplaySpan =
TimeSpan.FromSeconds(a_row!daySpan) 'Read this day's seconds
NewButton.butLoc = MyGlobals.CurrentLoc
NewButton.BackColor = Color.FromName(a_row!Color)
'Read the color of the button (by name)
NewButton.butShowMe = a_row!show ' Read the Show
or Don't Show value for the button
' Set up the Right-Click menu
NewButton.ContextMenuStrip = cmTimeButs
oTimeSliceCollection.Add(NewButton,
a_row("TimerID").ToString)
End If

Next
 

My Computer

C

Chris Dunaway

On May 10, 5:19 pm, Patrick A <[email protected]> wrote:

> I have a form where buttons are added by code.  I want to filter the
> buttons on the "Show" column in my data source unless the user has
> indicated otherwise, which sets MyGlobals.ShowAllButtons = True.
>
> The code below works, but I can't believe there is not a better way.
> I have tried to filter the Binding Source a variety of ways,
> Me.QRY_ButtonsBindingSource.Filter = "Show = True"
> Me.QRY_ButtonsBindingSource.Filter = "Show = 'True'"
> Me.QRY_ButtonsBindingSource.Filter = "Show =" & True
> Me.QRY_ButtonsBindingSource.Filter = "Show =" & "'True'"
> but with no results.
>
> Am I totally misunderstanding the concept of "where and how" to
> filter, or is there an easier way?
>
> Thanks,
>
> Patrick
>
>  Me.QRY_ButtonsTableAdapter.ClearBeforeFill = True
>
> Me.QRY_ButtonsTableAdapter.Fill(Me.L55TimerDataSet.QRY_Buttons)
>
>             Dim Row As Integer = 0
>
>             Dim ButRecds =
> L55TimerDataSet.Tables("QRY_Buttons").AsEnumerable '.Select("Show =
> True")
>
>             Dim sortedButRecds = From a_row In ButRecds Select a_row
>
>             'Get values - labels, meanings, colors, etc. fromthe DB.
>             For Each a_row In sortedButRecds    'Iterate through the
> collection.
>                 If MyGlobals.ShowAllButtons = False Then
>                     If a_row!show = True Then
>                         Row = Row + 1   'Increment up.
>                         NewButton = New MyButton(Me) ' Sets a new
> button
>                         Me.Panel1.Controls.Add(NewButton)  'Adds the
> new button to the form.
>                         NewButton.butID = a_row!TimerID.ToString
>                         NewButton.Name = (a_row!Position)   'Pull the
> TimerPos from DS and use it as a tag.
>                         NewButton.Text = (a_row!Label)  'Pull the
> butLabel from DS and use it as text.
>                         NewButton.butLabel = a_row!Label.ToString '
>                         NewButton.butNarr = a_row!Narrative.ToString
> 'Read the Work Description from the DB.
>                         NewButton.butDispCM = a_row!
> ClientMatter.ToString 'Read the Cli/Mat from the DB.
>                         NewButton.butTask = a_row!Task.ToString 'Read
> the Task Code from the DB.
>                         NewButton.butAct = a_row!Activity.ToString
> 'Read the Activity Code from the DB.
>                         NewButton.butDisplaySpan =
> TimeSpan.FromSeconds(a_row!daySpan)
>                         NewButton.butLoc = MyGlobals.CurrentLoc
>                         NewButton.BackColor = Color.FromName(a_row!
> Color) 'Read the color of the button
>                         NewButton.butShowMe = a_row!show ' Read the
> Show or Don't Show value for the button
>                         ' Set up the Right-Click menu
>                         NewButton.ContextMenuStrip = cmTimeButs
>                         oTimeSliceCollection.Add(NewButton,
> a_row("TimerID").ToString)
>                     End If
>                 Else
>                     Row = Row + 1   'Increment up..
>                     NewButton = New MyButton(Me) ' Sets a new button
>                     Me.Panel1.Controls.Add(NewButton) 'Adds the new
> button to the form.
>                     NewButton.butID = a_row!TimerID..ToString
>                     NewButton.Name = (a_row!Position)   'Pull the
> TimerPos from DS and use it as a tag.
>                     NewButton.Text = (a_row!Label)  'Pull the butLabel
> from DS and use it as text.
>                     NewButton.butLabel = a_row!Label.ToString '
>                     NewButton.butNarr = a_row!Narrative.ToString 'Read
> the Work Description from the DB.
>                     NewButton.butDispCM = a_row!ClientMatter.ToString
> 'Read the Cli/Mat from the DB.
>                     NewButton.butTask = a_row!Task.ToString 'Read the
> Task Code from the DB.
>                     NewButton.butAct = a_row!Activity.ToString 'Read
> the Activity Code from the DB.
>                     NewButton.butDisplaySpan =
> TimeSpan.FromSeconds(a_row!daySpan) 'Read this day's seconds
>                     NewButton.butLoc = MyGlobals.CurrentLoc
>                     NewButton.BackColor = Color.FromName(a_row!Color)
> 'Read the color of the button (by name)
>                     NewButton.butShowMe = a_row!show ' Read the Show
> or Don't Show value for the button
>                     ' Set up the Right-Click menu
>                     NewButton.ContextMenuStrip = cmTimeButs
>                     oTimeSliceCollection.Add(NewButton,
> a_row("TimerID").ToString)
>                 End If
>
>             Next
What is the Show column's data type? It seems like your first example
should work, since the Filter property is just a string.

Chris
 

My Computer

P

Patrick A

Chris,

Thanks for your reply. It's a Yes/No data type with a format of True/
False.

MsgBox(Me.QRY_ButtonsBindingSource.Filter.ToString) returns Show=True

Patrick

On May 12, 1:19 pm, Chris Dunaway <[email protected]> wrote:

> On May 10, 5:19 pm, Patrick A <[email protected]> wrote:
>
>
>
>
>

> > I have a form where buttons are added by code.  I want to filter the
> > buttons on the "Show" column in my data source unless the user has
> > indicated otherwise, which sets MyGlobals.ShowAllButtons = True.
>

> > The code below works, but I can't believe there is not a better way.
> > I have tried to filter the Binding Source a variety of ways,
> > Me.QRY_ButtonsBindingSource.Filter = "Show = True"
> > Me.QRY_ButtonsBindingSource.Filter = "Show = 'True'"
> > Me.QRY_ButtonsBindingSource.Filter = "Show =" & True
> > Me.QRY_ButtonsBindingSource.Filter = "Show =" & "'True'"
> > but with no results.
>

> > Am I totally misunderstanding the concept of "where and how" to
> > filter, or is there an easier way?
>

> > Thanks,
>

> > Patrick
>

> >  Me.QRY_ButtonsTableAdapter.ClearBeforeFill = True
>

> > Me.QRY_ButtonsTableAdapter.Fill(Me.L55TimerDataSet.QRY_Buttons)
>

> >             Dim Row As Integer = 0
>

> >             Dim ButRecds =
> > L55TimerDataSet.Tables("QRY_Buttons").AsEnumerable '.Select("Show =
> > True")
>

> >             Dim sortedButRecds = From a_row In ButRecds Select a_row
>

> >             'Get values - labels, meanings, colors, etc. from the DB.
> >             For Each a_row In sortedButRecds    'Iterate through the
> > collection.
> >                 If MyGlobals.ShowAllButtons = False Then
> >                     If a_row!show = True Then
> >                         Row = Row + 1   'Increment up.
> >                         NewButton = New MyButton(Me) ' Sets a new
> > button
> >                         Me.Panel1.Controls.Add(NewButton)  'Adds the
> > new button to the form.
> >                         NewButton.butID = a_row!TimerID.ToString
> >                         NewButton.Name = (a_row!Position)   'Pull the
> > TimerPos from DS and use it as a tag.
> >                         NewButton.Text = (a_row!Label)  'Pull the
> > butLabel from DS and use it as text.
> >                         NewButton.butLabel = a_row!Label.ToString '
> >                         NewButton.butNarr = a_row!Narrative.ToString
> > 'Read the Work Description from the DB.
> >                         NewButton.butDispCM =a_row!
> > ClientMatter.ToString 'Read the Cli/Mat from the DB.
> >                         NewButton.butTask = a_row!Task.ToString 'Read
> > the Task Code from the DB.
> >                         NewButton.butAct = a_row!Activity.ToString
> > 'Read the Activity Code from the DB.
> >                         NewButton.butDisplaySpan =
> > TimeSpan.FromSeconds(a_row!daySpan)
> >                         NewButton.butLoc = MyGlobals.CurrentLoc
> >                         NewButton.BackColor =Color.FromName(a_row!
> > Color) 'Read the color of the button
> >                         NewButton.butShowMe =a_row!show ' Read the
> > Show or Don't Show value for the button
> >                         ' Set up the Right-Click menu
> >                         NewButton.ContextMenuStrip = cmTimeButs
> >                         oTimeSliceCollection.Add(NewButton,
> > a_row("TimerID").ToString)
> >                     End If
> >                 Else
> >                     Row = Row + 1   'Increment up.
> >                     NewButton = New MyButton(Me) ' Sets a new button
> >                     Me.Panel1.Controls.Add(NewButton)  'Adds the new
> > button to the form.
> >                     NewButton.butID = a_row!TimerID.ToString
> >                     NewButton.Name = (a_row!Position)   'Pull the
> > TimerPos from DS and use it as a tag.
> >                     NewButton.Text = (a_row!Label)  'Pull the butLabel
> > from DS and use it as text.
> >                     NewButton.butLabel = a_row!Label.ToString '
> >                     NewButton.butNarr = a_row!Narrative.ToString 'Read
> > the Work Description from the DB.
> >                     NewButton.butDispCM = a_row!ClientMatter.ToString
> > 'Read the Cli/Mat from the DB.
> >                     NewButton.butTask = a_row!Task.ToString 'Read the
> > Task Code from the DB.
> >                     NewButton.butAct = a_row!Activity.ToString 'Read
> > the Activity Code from the DB.
> >                     NewButton.butDisplaySpan =
> > TimeSpan.FromSeconds(a_row!daySpan) 'Read this day's seconds
> >                     NewButton.butLoc = MyGlobals.CurrentLoc
> >                     NewButton.BackColor = Color.FromName(a_row!Color)
> > 'Read the color of the button (by name)
> >                     NewButton.butShowMe = a_row!show ' Read the Show
> > or Don't Show value for the button
> >                     ' Set up the Right-Click menu
> >                     NewButton.ContextMenuStrip = cmTimeButs
> >                     oTimeSliceCollection.Add(NewButton,
> > a_row("TimerID").ToString)
> >                 End If
>

> >             Next
>
> What is the Show column's data type?  It seems like your first example
> should work, since the Filter property is just a string.
>
> Chris- Hide quoted text -
>
> - Show quoted text -
 

My Computer

Top