StrataFrame Forum

BrowseDialog setting intial value

http://forum.strataframe.net/Topic29376.aspx

By Ian Johnston - 1/16/2011

Is there a way to set the intial value of a search field at runtime i.e filter a date field based on today's date using greater than or equal to?
By Ivan George Borges - 1/16/2011

Hi Ian.

There are two major ways of accomplishing this. One is through the SearchFields Values:

http://forum.strataframe.net/FindPost4275.aspx

Another one would be to work with the Searching event:

Help File -> Application Framework -> UI Layer -> Controls -> Browse Dialog -> Events (Searching Event)
By Ian Johnston - 3/13/2011

I am calling a browse dialog from a button on a standard form, I am filling the search criteria and calling the browse dialog. The dialog comes up with the expected results selected and when I click any where on the browse dialog for the first time I get the following message:

ArgumentException
  An item with the same key has already been added.

Source     : mscorlib

Stack Trace:
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogwindow.HandleSearchValueChanged(Control sourceControl, SearchFieldItem sourceFieldItem)
   at MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogwindow.HandleValidated(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnValidated(EventArgs e)
   at System.Windows.Forms.Control.PerformControlValidation(Boolean bulkValidation)


If I close the message everything works as expected and the result is returned as expected and no more messages. In the click event of the calling form I have the following code:

private void button1_Click(object sender, EventArgs e)

{

this.browseDialog1.AdvancedOptions = false;

this.browseDialog1.AllowHideResults = false;

this.browseDialog1.AllowSearchFieldsButton = false;

this.browseDialog1.SearchFields[0].InitialValue = comboBoxCarrier.Text.Trim();

this.browseDialog1.SearchFields[1].InitialValue = comboBoxCust.Text.Trim();

this.browseDialog1.SearchFields[2].InitialValue = comboBox1.Text.Trim();

this.browseDialog1.SearchFields[3].InitialValue = dateTimePickerBegin.Value.ToShortDateString();

this.browseDialog1.SearchFields[4].InitialValue = dateTimePickerEnd.Value.ToShortDateString();

this.browseDialog1.SearchFields[5].InitialValue = "";

this.browseDialog1.SearchFields[6].InitialValue = "";

if (this.browseDialog1.ShowDialog(true).Equals(DialogResult.OK))

{

listView1.Requery();

}

}

Any thoughts?

By Edhy Rijo - 3/13/2011

Hi Ian,

The error means that there is a duplicate field in the Search field collection and this is most likely to be when using a Date field for searching since we most use Greater than and Less than conditions.

this.browseDialog1.SearchFields[3].InitialValue = dateTimePickerBegin.Value.ToShortDateString();
this.browseDialog1.SearchFields[4].InitialValue = dateTimePickerEnd.Value.ToShortDateString();



To fix this, modify the BD and in the Search Field Criteria for the Ending Date field, enter a Unique Key to make it unique.  By default SF will automatically enter the field name, but you can and must change it to a unique one in this case.

Also, in general I prefer to use the Browse Dialog events to handle this situation problematically, so instead of having all the code in the button1, I would enter your code in the InitializedSerachFields events and instead of using index for the field name I would use the business object FieldNames enumeration so if in the future a field name changes at least my application will generate a compilation exception so I can fix it and also it looks better in code to see which fields are actually being initialized.  Here is a VB sample of this event:

Private Sub ServiceCallsBD_InitializeSearchFields(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ServiceCallsBD.InitializeSearchFields
        With Me.ServiceCallsBD
            .SearchFields(bizServiceCalls.bizServiceCallsFieldNames.CallDateTime.ToString).InitialValue = Now.ToString
            .SearchFields(bizServiceCalls.bizServiceCallsFieldNames.Notes.ToString).InitialValue = "My nice note"""
        End With
End Sub
By Ian Johnston - 3/13/2011

Thanks that fixed it

Ian
By Edhy Rijo - 3/13/2011

You are welcome Ian.