I have a project that I am working on which involves the need to set the ListView filter fields.
Back when I was much younger and far more naïve 🙂 I would brute force my want to locate the control (https://potatoit.kiwi/2010/10/10/manipulating-smart-office-column-header-filter-values/). Years later I saw the light and stumbled across the fields but I didn’t ever get around to posting about it. Of course, I couldn’t remember where I had found the fields nor could I find a posting about it on my blog so I did some investigation.
I also wrote some code around exploring what I thought was the appropriate field list and expanded that as it became more apparent that I was on the right track, until finally I wrote some functions to test that I would actually use.
As you can guess by the title, PositionFields are where the ListView filter TextBoxes are stored and as one would expect, they are stored in a list on the ListControl.
Below is a script which demonstrates retrieving and setting the filter TextBox values.
/*
** Name: test_SetListViewFields.js
** Panel: /B
**
** Description:
** this will demonstrate retrieving the values of the filter/position fields
** for the ListView, it also has some clean functions to do the retrieval/setting
**
**
** Written by:
** Scott Campbell (scott.campbell@potatoit.kiwi)
**
** History:
** 20170218 SAC * started
**
*/
import System;
import System.Windows;
import System.Windows.Controls;
import MForms;
import Mango.UI;
package MForms.JScript
{
class test_SetListViewFields
{
var gDebug = null;
var gController = null;
var gContent = null;
var gListControl = null;
var gListView = null;
public function Init(element: Object, args: Object, controller : Object, debug : Object)
{
gDebug = debug;
gController = controller;
gContent = controller.RenderEngine.Content;
gDebug.Debug("test_SetListViewFields Init()");
gListView = gController.RenderEngine.ListViewControl;
gListControl = gController.RenderEngine.ListControl;
var positionFieldName = "";
if(null != gListControl && null != gListControl.PositionFields)
{
gDebug.Debug("Position Field Count: " + gListControl.PositionFields.Count);
for(var i = 0; i < gListControl.PositionFields.Count; i++)
{
var currentPositionField = gListControl.PositionFields[i];
if(null != currentPositionField)
{
gDebug.Debug(" +-- PositionField[" + i + "] Type: " + currentPositionField.GetType());
if(currentPositionField.GetType().ToString() == "System.Windows.Controls.TextBox")
{
positionFieldName = currentPositionField.Name;
gDebug.Debug(" +-- PositionField[" + i + "] is a TextBox, it's name is: " + currentPositionField.Name);
gDebug.Debug(" +-- PositionField[" + i + "] is a TextBox, it's value is: " + currentPositionField.Text);
gDebug.Debug(" +-- PositionField[" + i + "] testing the retrieving of the value: '" + getPositionTextBoxValue(gListControl, positionFieldName) + "'");
gDebug.Debug(" +-- PositionField[" + i + "] is a TextBox, we will now set its value to " + i);
setPositionTextBoxValue(gListControl, positionFieldName, i.ToString());
}
}
}
}
}
private function setPositionTextBoxValue(aListControl : ListControl, aFieldName : String, aValue : String)
{
var textBox : TextBox = getPositionTextBox(aListControl, aFieldName);
if(null != textBox)
{
textBox.Text = aValue;
}
}
private function getPositionTextBoxValue(aListControl : ListControl, aFieldName : String)
{
var result = "";
var textBox : TextBox = getPositionTextBox(aListControl, aFieldName);
if(null != textBox)
{
result = textBox.Text;
}
return(result);
}
private function getPositionTextBox(aListControl : ListControl, aFieldName : String)
{
var result : TextBox = null;
if(null != aListControl && false == String.IsNullOrEmpty(aFieldName))
{
if(null != aListControl.PositionFields && aListControl.PositionFields.Count > 0)
{
for(var i = 0; i < aListControl.PositionFields.Count; i++)
{
var positionField = aListControl.PositionFields[i];
if(null != positionField && positionField.GetType().ToString() == "System.Windows.Controls.TextBox" && positionField.Name == aFieldName)
{
result = positionField;
break;
}
}
}
}
return(result);
}
}
}
And this is the output from the script
