How to get all the textBoxes in the UserControl added into GridView - winrt-xaml

On the Page, I add UserControl into GridView dynamically. So, each UserControl can contain different kind of controls ( TextBox, CheckBox, Radio Button)
say , the name of UserControl is : UserForm.
problem :
How to get a collection of control using VisualTreeHelper and check if textBox is empty.
I found a code similiar to this problem and modified it but not working.
I dont know what this means and if this is required?
list.AddRange(AllTextBoxes(child))
Should I use MyList.Select() or MyList.Where() ?
void FindTextBoxes()
{
List <TextBox> MyList = AllTextBoxes(UserForm);
var count = MyList.Where(x= > if(string.IsEmptyOrNull(x.Text));
}
List <TextBox> AllTextBoxes(DependencyObject parent)
{
var list = new List <TextBox>();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
if (child is TextBox)
list.Add(child as TextBox);
list.AddRange(AllTextBoxes(child));
}
return list;
}

Here's what I use.
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var textBoxes = AllChildren(MyGridView).Where(x => x is TextBox);
}
public IEnumerable<Control> AllChildren(DependencyObject parent)
{
for (int index = 0; index < VisualTreeHelper.GetChildrenCount(parent); index++)
{
var child = VisualTreeHelper.GetChild(parent, index);
if (child is Control)
yield return child as Control;
foreach (var item in AllChildren(child))
yield return item;
}
}
Best of luck!

Related

how to filter items from listbox?

i want to filter items from listbox when i typed in combobox ..
suppose, when i type "A" in combobox then listbox display items which contains "A" anywhere.. without using SQL STATEMENT...
below is my code..
private void FillListBoxes()
{
lbSearch.DisplayMember = "CatName";
lbSearch.ValueMember = "catID";
int count = FillList.Rows.Count;
if (count > 0)
{
lbSearch.Items.Clear();
for (int i = 0; i < count; i++)
{
lbSearch.Items.Add(FillList.Rows[i]["CatName"].ToString());
}
}
}
You need to hold a list with all the items, assume AllItems is the name of this list. then you can try:
private void FillListBoxes()
{
string check=combobox1.Text;
lbSearch.Items.Clear();
foreach (string item in AllItems)
{
if (item.Contains(check);
{
lbSearch.Items.Add(item);
}
}
}

How do I add a click event handler to a TextBox's DeleteButton?

I have a TextBox in one of my Windows Runtime app's Pages. When there is text in the TextBox, it shows a black cross which, when clicked, clears the TextBox. Apparently this is the DeleteButton from the default template, and there are loads of questions on SO about how to remove it. I don't want to remove it, but I do want to add an event handler so I know when it is clicked.
How do I add a click event handler to a TextBox's DeleteButton? I'd prefer an answer that saves me having to make a copy of the template.
<TextBox x:Name="TestTextBox" Loaded="TestTextBox_Loaded" Width="300" Height="100"></TextBox>
The easiest way is to use the VisualTreeHelperExtension from the WinRTXamlToolkit (or as NuGet package).
With the TreeHelper you can easy access the button:
private void TestTextBox_Loaded(object sender, RoutedEventArgs e)
{
var deleteButton = TestTextBox.GetChildByName<Button>("DeleteButton");
deleteButton.Click += deleteButton_Click;
}
void deleteButton_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
I use this function:
public static T GetChildByName<T>(this DependencyObject parent, string childName) where T : DependencyObject
{
// Confirm parent and childName are valid.
if (parent == null) { return null; }
T foundChild = null;
int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < childrenCount; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(parent, i);
// If the child is not of the request child type child
var childType = child as T;
if (childType == null)
{
// recursively drill down the tree
foundChild = GetChildByName<T>(child, childName);
// If the child is found, break so we do not overwrite the found child.
if (foundChild != null) { break; }
}
else if (!string.IsNullOrEmpty(childName))
{
var frameworkElement = child as FrameworkElement;
// If the child's name is set for search
if (frameworkElement != null && frameworkElement.Name == childName)
{
// if the child's name is of the request name
foundChild = (T)child;
break;
}
// Need this in case the element we want is nested
// in another element of the same type
foundChild = GetChildByName<T>(child, childName);
}
else
{
// child element found.
foundChild = (T)child;
break;
}
}
return foundChild;
}

I need to implement a linerlayout in android and populate with a list of items. I am doing so because i want the list to be non scrollable?

final LinearLayout l = (LinearLayout) findViewById(R.id.linearlist);
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textlength = et.getText().length();
array_sort.clear();
for (i = 0; i < namelist.length; i++) {
if (textlength <= namelist[i].length()) {
if (et.getText()
.toString()
.equalsIgnoreCase(
(String) namelist[i].subSequence(0,
textlength))) {
array_sort.add(namelist[i]);
if (et.getText().length() == 0) {
// array_sort.remove(namelist[i]);
array_sort.clear();
Just instantiate new TextView on the fly and add them to your layout.
TextView view = new TextView(context);
l.addView(view);

Read Check Box, Radio Button Name and values from PDF using iText Sharp

I have a fillable PDF contains CheckBoxes and RadioButtons and TextBox.
How do i get the CheckBox Name and its value also how do we know that it is a checkbox / Radio Button?
i'm using iTextSharp and have look at my below code
PdfReader pdfReader = new PdfReader(FileName);
pdfReader.SelectPages("37");
MemoryStream oStream = new MemoryStream();
PdfStamper stamper = new PdfStamper(pdfReader, oStream);
AcroFields form = stamper.AcroFields;
if (form.Fields.Count() > 0)
{
IDictionary<string,AcroFields.Item> oDic= form.Fields;
foreach (string FieldName in oDic.Keys)
{
//FieldName - CheckBox name; i need to confirm that is a Checkbox...
}
foreach (AcroFields.Item oItem in oDic.Values)
{
// how do we get check box values
}
}
The following code may help you out, if you still need it. It only works for AcroForms
int BUTTON = 1;
int CHECK_BOX = 2;
int RADIO_BUTTON = 3;
int TEXT_FIELD = 4;
int LIST_BOX = 5;
int COMBO_BOX = 6;
PdfReader pdfReader = new PdfReader(path);
AcroFields af = pdfReader.AcroFields;
foreach (var field in af.Fields)
{
bool isRadio = RADIO_BUTTON == af.GetFieldType(field.Key));
}
Edit:
Also, field.Key is the name of the field and field.Value is the value at it.
For checkboxes, if(field.Value == "Yes") then it is selected... if it is anything else, it is not selected.
Edit:
And I just found how tro get Radio Button options, if you are needing them.
myKey k = new myKey(field.Key, af.GetField(field.Key), af.GetFieldType(field.Key));
if (k.isRadio())
{
try { k.options.AddRange(af.GetAppearanceStates(k.key)); }
catch { }
}
Keys.Add(k);
Radio buttons, checkbox and buttons are all actually the same type of field but with different flags set. You can see the flags in the PDF Spec section 12.7.4.2.1 Table 226.
int ffRadio = 1 << 15; //Per spec, 16th bit is radio button
int ffPushbutton = 1 << 16; //17th bit is push button
For a given Field you want to get the Widgets associated with it. Usually this is just one but can be more so you should account for this.
PdfDictionary w = f.Value.GetWidget(0);
Button fields will have their field type (/Ft) set to /Btn so check for that
if (!w.Contains(PdfName.FT) || !w.Get(PdfName.FT).Equals(PdfName.BTN)) {continue;/*Skipping non-buttons*/ }
For the current Widget get the optional field flags (/Ff) value or use zero if it doesn't exist.
int ff = (w.Contains(PdfName.FF) ? w.GetAsNumber(PdfName.FF).IntValue : 0);
Then just some simple math:
if ((ff & ffRadio) == ffRadio) {
//Is Radio
} else if (((ff & ffRadio) != ffRadio) && ((ff & ffPushbutton) != ffPushbutton)) {
//Is Checkbox
} else {
//Regular button
}
Below is a full-working C# WinForm 2011 app targeting iTextSharp 5.2.0 that shows off all of the above looking at a file called Test.pdf living on your desktop. Just add some logic to the conditionals to handle each button type.
using System;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text.pdf;
namespace WindowsFormsApplication3 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
var testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
PdfReader reader = new PdfReader(testFile);
var fields = reader.AcroFields;
int ffRadio = 1 << 15; //Per spec, 16th bit is radio button
int ffPushbutton = 1 << 16; //17th bit is push button
int ff;
//Loop through each field
foreach (var f in fields.Fields) {
//Get the widgets for the field (note, this could return more than 1, this should be checked)
PdfDictionary w = f.Value.GetWidget(0);
//See if it is a button-like object (/Ft == /Btn)
if (!w.Contains(PdfName.FT) || !w.Get(PdfName.FT).Equals(PdfName.BTN)) { continue;/*Skipping non-buttons*/ }
//Get the optional field flags, if they don't exist then just use zero
ff = (w.Contains(PdfName.FF) ? w.GetAsNumber(PdfName.FF).IntValue : 0);
if ((ff & ffRadio) == ffRadio) {
//Is Radio
} else if (((ff & ffRadio) != ffRadio) && ((ff & ffPushbutton) != ffPushbutton)) {
//Is Checkbox
} else {
//Regular button
}
}
this.Close();
}
}
}
C# with System.Linq included
for radio buttons , get which option is selected from all the options in radio form, print also all the choice options by their specified name in Adobe Acrobat Pro
AcroFields fields = reader.AcroFields;
List<string> fldNames = new List<string>(fields.Fields.Keys);
if (fldNames.Count > 0) //am gasit cel putin un acroform
{
foreach (string fldname in fldNames)
{
int tip = fields.GetFieldType(fldname);
if (tip == 3) //choice / radio
{
Console.WriteLine("radio form");
string[] valori = fields.GetListSelection(fldname);
foreach (string s in valori)
Console.WriteLine(s + " ");
Console.WriteLine("selected from radio form options");
string[] valori2 = fields.GetAppearanceStates(fldname);
//Console.WriteLine(valori2.Length);
var val2 = (from string c in valori2
where (c.ToLower().CompareTo("off") != 0)
select c).ToList();
if (val2.Count > 0)
foreach (string s2 in val2)
Console.WriteLine(s2 + " ");
}
}
}

Re-order the column numbers when item deleted in sharepoint list

I have a list "Numbers". Items in this list are from 1 to 10(a column other than ID will display this number).
item[1st item]["order"]=1;item[2nd item]["order"]=2;......item[10th item]["order"]=10;
If any item got deleted, lets say item[6th item]["order"]=6; got deleted, then the items in that list should be 1 to 9 i.e. when the item gets deleted, automatically have to order these values. Here i am using ItemDeleted Event Handler to achieve this functionality. But its not working. My code is :
public override void ItemDeleted (SPItemEventProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
string mysiteUrl = properties.WebUrl;
SPSite mysite = new SPSite(mysiteUrl);
SPWeb myweb = mysite.OpenWeb();
myweb.AllowUnsafeUpdates = true;
SPList mylist = myweb.Lists["Numbers"];
for (int i = 0; i < mylist.ItemCount; i++)
{
int order = int.Parse(mylist.Items[i]["order"].ToString());
if (!(i + 1 == order))
{
int categoryId = int.Parse(mylist.Items[i]["ID"].ToString());
SPListItem item = mylist.GetItemById(categoryId);
item["Priority"] = i + 1;
mylist.Update();
}
}
myweb.AllowUnsafeUpdates = false;
});
}
I installed and activated the feature. But its not working. I dont know what going wrong here.Please help me on this issue
Try calling Update() on the SPListItem and not the SPList

Resources