Mattersphere Developers Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
avatar
Heather@FootAnstey
Posts : 57
Join date : 2018-12-19

[Search Lists] Can you change the “Filter Results” label? Empty [Search Lists] Can you change the “Filter Results” label?

Fri 17 Apr 2020 - 14:53
Original Post: Kirsty 12/09/2013 11:29:53

"Is it possible to change the wording of the label “Filter results:” label on a search list (between the form part and the resultsbox)or is this hard coded?"


Responses:

technical 12/09/2013 12:11:09
"Hi Kirsty,
Not sure if there is a direct property that you can use to update that label, but you could try recursively getting the .Controls property of the EnquiryForm or Wizard and then testing for Label types until you find the object that represents the label and then updating its Text Value?
With Recursion you just have to be careful not to create infinate loops, but they work really well for finding things in a tree based structure like how controls are stored on Winforms or FWBS Enquiry Forms.
something like the below(Note this is off the top of my head and hasnt been tested at all so will need work)
public List GetLabelControls(Control currentControl)
{
List myLabels = new List(); foreach(objectmyControl in currentControl.Controls)
{
if(myControl is System.Windows.Controls.Label)
{
myLabels.Add(myControl);
}
else
{
if(myControl is System.Windows.Controls.Control)
{
//Recersive bit, calling the function again myLabels.AddRange((GetLabelControls(myControl));
}
}
}
return myLabels;
}

//Call to get all the labels
List Labels =GetLabelControls(EnquiryForm.Controls);
//Loop though the controls looking for the text on the label foreach(System.Windows.Controls.Label currentLabel in Labels)
{
if(currentLabel.Text.Equals(“Filter results”))
{
//Set it to something else currentLabel.Text = “My new Label”; break;
}
}

Hope that helps Phil"

Kirsty 18/09/2013 11:10:50
"Thanks for that Phil. Using your idea I have used the following code in the enquiryLoaded event of thesearch list's formto cycle through & set the label & resize the box.
using System.Reflection; using System.Text;
using System.Collections.Generic; using FWBS.Common.Collections;

private List<Control> GetAllControls(Control container, List<Control> list)
{
StringBuilder sb = new StringBuilder(); foreach (Control c in container.Controls)
{
if (c.Name == “txtSearch”)
{
c.Text = “Filter within results:”;
PropertyInfo[] properties = c.GetType().GetProperties(); foreach (PropertyInfo pi in properties)
{
if (pi.Name == “CaptionWidth”)
{
pi.SetValue(c,500,null);
}
}
}
else list.Add(c);
if (c.Controls.Count > 0) list = GetAllControls(c, list);
}
return list;
}

private List<Control> GetAllControls(Control container)
{
return GetAllControls(container, new List<Control>());
}


protected override void EnquiryLoaded(object sender, System.EventArgs e)
{
List<Control> allTextboxes = GetAllControls(this.EnquiryForm.ParentForm); StringBuilder sb = new StringBuilder();
foreach (Control c in allTextboxes)
{
if (c is TextBox)
{
c.Left = 130;
c.Width = 1000; break;
}
}
}
"

technical 18/09/2013 11:26:31
"No problems, glad it was useful. Phil"



Back to top
Permissions in this forum:
You cannot reply to topics in this forum