Goal - To cycle through a Tableview and obtain the input field type and value, ignoring label. The view is entirely based in c# code as the tableview will vary constantly.
So far in a for each look I can cycle through to the point of:
var x = (object)myViewCellInputItem[0];
For now I have set up a textview which has two elements, label and entry. The entry object I can obtain in var x as above.
Goal: Get the "Text" attrtibute.
Entry ent = (Entry)x;
string text = ent.Text;
The code above achives it. What I am face with is other Views such as DatePicker etc.
I was considering:
private string GetProperty(object XamarinObj)
{
string output;
Type t = XamarinObj.GetType();
if (t == typeof(Xamarin.Forms.Entry))
{
Entry ent = (Entry)XamaninObj;
return ent.Text.ToString();
}
else if {
.... repeat for other types
}
}
A unhelpful friend suggested to use Linq to query x to find "Text", "Items", "Date" etc but wouldn't show me how!
Your thoughts.
Well after much searching this is the route I went down. I can obtain all View/Text/Cell data I wish across all three platforms.
Related
I have a database which it's schema is as follows:
As you can see, We have WareCategories which will be category of the wares i'm going to be working in my website. WareTypes which will be Definition of each Item type. Categories define properties in the table WarePropertyDefinitions and WareProperties define values for each property that has been defined in WarePropertyDefinitions table.
Now i have a search page that users search for items in OldWares and user selects category and i show the user all properties defined in WarePropertyDefinitions and user fills the data if he likes better results. But my problem is that i can't filter WareTypes based on WareProperties because it's from the type ICollection and i can't access filter options.
How can i apply this kind of filtering based on properties?
Thanks in advance...
Edit:
This is a part of the code i'm presenting to describe more:
var lst = WareCategory.GetItem(Convert.ToInt32(ddlChildren.SelectedValue)).WarePropertyDefinitions.ToList();
foreach (var ListItem in lst)
{
var value = BaseHelper.FindFormValue("PropertyValue" + ListItem.Id.ToString());
if (!string.IsNullOrEmpty(value))
{
query = query.Where(m => m.WareType.WareProperties.);
}
}
}
This segment of code is in my search function and as you can see i'm going to generate a list of items in WarePropertyDefinition that user selected via a drop down menu called ddlChildren. I'm going to iterate in this definition and user entered value for each property (the value variable will hold the value user entered and i will check if user have entered anything in the textbox) i will include it in where section (through this i will add it in where clause that ultimately filters my selection). but as you can see the code is incomplete because i don't know how to complete it.
Use the Any() extension method, for example:
query = query.Where(m => m.WareType.WareProperties.Any(wp => wp.Id == 5));
I have fixed the my problem by this code:
query = query.Where(m => m.WareType.WareProperties.Any(wp => wp.WarePropertyDefinition_Id == ListItem.Id && wp.TextValue == value));
but because #user3159792's answer was the basic of my problem i have selected his answer as the default answer to my problem. very thanks.
I need to programmatically delete items in Sitecore, but if they are being referenced by other items, then I need to update those items to reference some other item.
In the UI, Sitecore provides a dialog box for doing this, but the item.Delete() and item.Recycle() methods don't appear to have any overrides for something similar. I can use Sitecore.Globals.LinkDatabase.GetItemReferrers(item, true) to get the referring items, but I would still need to get the specific fields from those items and update them according to their type.
To the best of my knowledge, as long as the item's ID gets replaced in the referring item's field, the field's type shouldn't matter. One exception would be the Rich Text field type, where links in the HTML have the following format:
So we should be able to do two simple replacements. One for the item ID and one for the lower-cased, unhyphenated ID.
First, get the referring item links, and create the replacement strings.
var links = Sitecore.Globals.LinkDatabase.GetItemReferrers(item, true);
string oldIdWithoutBraces = item.ID.ToString().Replace("{", "").Replace("}", "");
string newIdWithoutBraces = newItem.ID.ToString().Replace("{", "").Replace("}", "");
string oldIdForHyperlinks = oldIdWithoutBraces.ToLower().Replace("-", "");
string newIdForHyperlinks = newIdWithoutBraces.ToLower().Replace("-", "");
Then, for each referring item link, get its referring field and update the item IDs in it.
using (new Sitecore.SecurityModel.SecurityDisabler())
{
foreach (var link in links)
{
var sourceItem = link.GetSourceItem();
var fieldId = link.SourceFieldID;
var field = sourceItem.Fields[fieldId];
sourceItem.Editing.BeginEdit();
try
{
field.Value = field.Value
.Replace(oldIdWithoutBraces, newIdWithoutBraces)
.Replace(oldIdForHyperlinks, newIdForHyperlinks);
}
catch
{
sourceItem.Editing.CancelEdit();
}
finally
{
sourceItem.Editing.EndEdit();
}
}
}
Afterward, the original item can be deleted.
item.Recycle();
Some Sitecore field types (such as Image fields) have a path attribute, which should be updated as well, but it shouldn't be difficult to work that into the code above.
We've got problem with filtering for some of our columns in devexpress gridcontrol. We add the column dynamically (bound-type column) to the grid. The values from the source objects are long type. In the cells it seems that values are fine (since they're aligned to the right without any custom formating on our side) however in filter popup values behave like strings.
For example data set like 1,2,5,11,22,37 the filter list is sorted like 1,11,2,22,5,37 (just like strings) and when we choose one of the available values the filtering does not work (i mean, grid becames empty). Even filters like "Non empty cells" does not work, but when we choose "empty cells" only few from few thousand rows are shown even if most of the cells have no values.
It is important to point out that only dynamically added columns behave that way, the few columns we create every time our module runs work as intended.
The data source is a container (List like).
We're using DevExpress 13.2.
Example of creating 'custom column'
void CreateColumn(GridColumn gridColumn, string fieldName = null, string caption = null, bool visible = true,
bool readOnly = true, UnboundColumnType unboundType = UnboundColumnType.Bound,
int columnWidth = int.MinValue, int minColumnWidth = int.MinValue)
{
gridColumn.Caption = caption;
if (fieldName != null)
gridColumn.FieldName = fieldName;
gridColumn.Visible = visible;
gridColumn.OptionsColumn.ReadOnly = readOnly;
gridColumn.OptionsColumn.AllowEdit = !readOnly;
gridColumn.UnboundType = unboundType;
gridColumn.OptionsFilter.AllowAutoFilter = true;
gridColumn.FilterMode = ColumnFilterMode.Value;
gridColumn.OptionsFilter.AutoFilterCondition = DevExpress.XtraGrid.Columns.AutoFilterCondition.Contains;
if (columnWidth != int.MinValue)
{
gridColumn.Width = columnWidth;
gridColumn.OptionsColumn.FixedWidth = true;
}
if (minColumnWidth != int.MinValue)
gridColumn.MinWidth = minColumnWidth;
}
GridColumn gridColumn = new GridColumn();
CreateColumn(gridColumn, "someName", "someCaption", true, true);
View.Columns.Add(newGridColumn);
That's how it goes in our code (striped most of not related code just to give example process).
#edit
There's invalid cast exception when we add filter like this:
ColumnFilterInfo filter = GetFilter(); //cant really post code of this
ourGrid.MainView.ActiveFilter.Add(column, filter); // VS points here
Unfortunately it doesnt say what and where (except some 'lambda expression') exception is being thrown.
Of course column is the column mentioned above.
#edit
I've found new "tip". The FilterItem objects contain strings for sure, however they should contain long values. How can we influence the creation of these or atleast where to check why those are created like that (we dont do it manually)?
#Edit 19.11.2015
Alright, I had some breakthrough. The columns ('custom') thanks to our mechanism guess their type just fine. Then only problem is that infact our values which custom columns use are stored in Dictionary<string,object>-like collection and we think that thanks to PropertyDescriptor type for columns is fine, but for some reason FilterItem objects have Value of string. We belive that's because DX filter mechanism can't really guess type of "object" so it uses simple ToString on it so FilterItem.Value is string type instead column's data type.
How to overcome this?
We've found the solution and the mistake was on our side. Column creation etc is fine. Somewhere deep, someone has changed value types.
I'm having trouble accessing the value of a calculated field from a list which is in a lookup field on another list in codebehind for SharePoint.
A ListFieldIterator on a page displays a load of options to a user. I need to perform some back-end validation on some particular selections the user has made.
I have a list called "Event Type" from which a user can select Play, performance, display etc. This list has 4 columns - description, enabled, default and filtered. Filtered is a calculated column which is generated based upon the options chosen on the other columns.
The list Events has a column which is a lookup to this list, and which displays the filtered column.
Now on the page this all works great. The options are displayed to the user and they can make their selection. Before adding the calculated field I could access the choice made by doing the below
SPFieldLookup eventTypeField = ListFieldIterator.Item.Fields.GetField("Event_x0020_Type") as SPFieldLookup;
if (eventTypeField.GetFieldValueAsText(ListFieldIterator.Item["Event_x0020_Type"]) == "Performance")
{
// some other logic
errorMessages.Add("There is an error here");
}
Now however when accessing the field in this way I just get an empty string back.
If I attempt to access the chosen item with
string value = eventFields.Item["Event_x0020_Type_x0020_1"].ToString();
Then I get back "8" which is the position in the list of the item I chose. (it changes based on what item in the list I select)
This post Get value of calculate field seems related but I can't see an obvious way to get a calculated field from the lookupfield.
Any suggestions appreciated
It turns out that when using either a lookup column or a lookup column with a calculated field in, as I was, I was going about things the wrong way. This post put me onto the solution. The code is also below.
Essentially I need to access the value stored in the control of the ListFieldIterator and not the value from the item. The code below (from the link above) provides a nice way to do this.
public static List<T> GetControlsOfType<T>(this ControlCollection controls)
{
List<T> resultList = new List<T>();
foreach (Control control in controls)
{
if (control is T)
resultList.Add((T)((object)control));
if (control.Controls.Count > 0)
{
resultList.AddRange(GetControlsOfType<T>(control.Controls));
}
}
return resultList;
}
public object GetFieldValue(ListFieldIterator lfi, string fieldName)
{
FormField formField = lfi.Controls.GetControlsOfType<FormField>().Where(f => f.FieldName == fieldName).FirstOrDefault();
if (formField == null) return null;
return formField.Value;
}
I'm trying to find a way to to do something that I think must be possible but I'm just missing the point on - so hopefully someone can give me a bit of a nudge :)
I'm utilising databinding in ASP.NET (viewstate turned off - so using controlstate for a few things here and there) to render a repeater (repeaterPriceClasses) that has a repeater within each itemtemplate (repeaterPriceBands). Basically this renders a table out of some text and a dropdownlist in each cell.
I'm trying to find a way to enumerate the repeaterOuter inside the event handler of a button to give me a list of all of the originally bound elements that have now got a dropdownlist with a value of >0, along with what that value is.
public Dictionary<Price, int> SelectedPrices
{
get
{
var sel = new Dictionary<Price, int>();
foreach(RepeaterItem itemClass in repeaterPriceClasses.Items)
{
var repeaterPriceBands = itemClass.FindControl("repeaterPriceBands") as Repeater;
foreach(RepeaterItem itemBand in repeaterPriceBands.Items)
{
var context = (Price)itemBand.DataItem;
var listQty = itemBand.FindControl("listQty") as DropDownList;
if(listQty.SelectedValue.ToInt32() > 0)
{
sel.Add(context, listQty.SelectedValue.ToInt32());
}
}
}
return sel;
}
}
Now this fails because the itemBand.DataItem is always null after databinding has finished.
What technique should I use to get around this?
Hidden field with primary keys in it
(not ideal as can be abused and adds
weight to the page)
Lookup from
original cached data based on indexes
(just seems wrong)
or something
else/better...?
EDIT: Is there any more information that I could provide to help this get answered?
You can try adding extra attributes to your HTML elements in the ItemDataBound event when DataItem is available.
ddlSomething.Attributes["Attribute1"] = dataItemObject.PropertyName;
[Edit]
Apart from using attributes, you can render some array containing JSON objects like this, for each row.
var repeaterItemAttributes = [ { Prop1: val1, Prop2: val2, ... }, { ... }, ... ]
So, by using this, you won't have to render the attributes, and your code will be XHTML compliant too (tho its not required). You can then loop through the object array and read any property you like. You can also apply the light encryption you were talking about to the property values.
[/Edit]