I have added item in the ComboBox.I am not able to retrieve the selected item if I Select some Item in the combobox.
Most of the combox Propertise return Object Type and if If I try to do ToString() on the object it return Weird Value.
I tried these Propertise.
MainPage::cmbDeviceList_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e){
auto str = cmbDeviceList->SelectedItem->ToString;
auto str1 = cmbDeviceList->SelectedValue->ToString();
}
My Query is
How to Retrieve the items from the combobox On user selection
Why Most of the properties return Object.Is the purpose of keeping Object is to allow developer to insert class struct?
Finally I got Answer.
It should be
auto str = (String^) cmbDeviceList->SelectedItem;
But Still Not clear Why it is like that.
Related
In cppcx, I used to have this:
auto button = safe_cast<ContentControl ^>(obj);
if (auto text = dynamic_cast<Platform::String^>(button->Content)) {
return text->Data();
}
When I try to do this to convert this code to cppwinrt:
auto button = obj.as<winrt::ContentControl>();
if (auto text = button.Content().try_as<winrt::hstring>()) {
return text.c_str();
}
I get the following error:
Error (active) E0312 no suitable user-defined conversion from "winrt::impl::com_refwinrt::hstring" to "wchar_t*" exists
I was hoping I would get a winrt::hstring as a result of the try_as and I can get the .c_str() from it, but I am getting a winrt::impl::com_refwinrt::hstring instead. What am I missing?
It looks like you want to unbox a scalar value behind an IInspectable interface (see Boxing and unboxing scalar values to IInspectable with C++/WinRT). For unboxing you'll want to use the unbox_value function template:
auto button = obj.as<winrt::ContentControl>();
if (auto text = unbox_value<winrt::hstring>(button.Content())) {
return text.c_str();
}
Although it's questionable, whether you really want to return a pointer that points into the middle of some data owned elsewhere. It's probably best to just return an hstring by value. String handling in C++/WinRT has more information on the topic.
How to get 'No User found' message from the below variable in Node.js
{"error":["No User found."]}
You can do it like this:
var data = {"error":["No User found."]};
alert(data.error[0]);
The outer object has a property "error". That property, then contains an array from which you want the first element in the array (index 0).
So, you get the error property with data.error. And, then you reach into the array and get the first element with data.error[0].
You need to iterate through this object with a for loop and grab the value based on the name of the property.
for(item in obj){
console.log(obj[item]);
}
You can use an if statement and the match method if you need to make sure that the property name is 'error'.
Here is my fiddle:
http://jsfiddle.net/nhmaggiej/eajqzxfr/
I have a simple query which is
select distinct roleid,firstname,lastname where role_id='210';
I am using the same query for fetching the different lists such as projectnames ,projectmanagers name,developers...etc..based on the roleid that I am passing.
My problem is I need to run the above query in a single shot by passing all the roleid and retrieve them in a single hit and assign those list to different list such as managers list ,developers list ,testers list ..etc and send it to the UI putting them in a linked hasmap.
Example
LinkedHashMap<String, List<SelectItem>> results = new LinkedHashMap<String, List<SelectItem>>();
List<SelectItem> getProjectManager = getProjectManager(xxx);
List<SelectItem> getResourceOwnerSE = getResourceOwner(yyy);
List<SelectItem> getReqLeadPri = getReqLeadPri(zzz);
results.put("getProjectManager", getProjectManager);
results.put("getResourceOwner", getResourceOwnerSE);
results.put("getReqLeadPri", getReqLeadPri);
return results;
All the above methods getProjectManager(xxx),getResourceOwner(yyy),getReqLeadPri(zzz) runs with same query as mentioned above but passing different roleid xxx,yyy,zzz.
I don't know how to fetch a different list from a single query passing different parameters and assign to the list and return the results.
I am trying to achieve this because the UI is very slow when I try to get the lists individually from UI <-> DB each time when calling the same query passing different parameters each time for fetching different list.
Hence, I am trying to get the results in a single shot.
If you want to fir only one sql statement you can use ResultSetExtractor
public class SelectItemResultSetExtractor implements ResultSetExtractor<LinkedHashMap<String, List<SelectItem>>>{
public LinkedHashMap<String, List<SelectItem>> extractData(ResultSet rs) throws SQLException,
DataAccessException {
LinkedHashMap<String, List<SelectItem>> result = new ...
//put the 3 categories with empty arraylists
while(rs.next()){
SelectItem item= new SelectItem();
item.setRoleid(rs.getInt(1))
item.setFirstName(rs.getInt(2));
item.setLastName(rs.getString(3));
//if item.getRoleid() is ProjManager
// then put in the list of the ProjManager
result.get("ProjManager").add(item);
//if item.getRoleid() is ResourceOwnerSE
// then put in the list of the ResourceOwnerSE
...
}
return result;
}
}
I have a select that I get Json post with http, but I try to sets initially selected index but there is nothing in the list do not select anything. because the json is great.
public AppMainScreen() {
loadLists();
MySelect = new ObjectChoiceField( "Select: ", new Object[0], 3 );
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
vfm.add(MySelect);
add(vfm);
}
This statement appears wrong to me:
new ObjectChoiceField( "Select: ", new Object[0],3);
The second parameter to this constructor is supposed to be an array of objects whose .toString() method will be used to populate the choices. In this case, you have given it a 0 length array, i.e. no Objects. So there is nothing to choose. And then you have asked it to automatically select the 3rd item, and of course there is no 3rd item.
You should correct the code to actually supply an object array.
One option to make it easy is have your JSON load actually create a String array with one entry per selectable item. Then you use the index selected to identify the chosen item.
I had a similar question before, but this is a few steps beyond that so here we go:
I am trying to access values in a category in Tridion 2011. I am using the Razor TBB and using this code to do it:
#foreach (var keyword in Publication.MetaData.myCategory) {
#: Hello World!
}
I have set up a metadata schema with a field that has an xml name of "myCategory" attached to my publication. If I run this on the publication where myCategory is a Text field, this code works... kind of. It treats EACH character as a separate value of the keyword variable... so if I enter the text "one", what prints is "Hello World! Hello World! Hello World!", and if I just have "o" as the value, it prints "Hello World!".
Bizarre as that is (and I'd like to know why on that too), what I really want the field to be a "Values will be selected from a list" type of field, pointing to my category in Categories and keywords. When I do this, and the value of myCategory changes to the value of the item selected in the dropdown for this type of field instead of direct text entry, the code no longer works and gives this error:
Cannot implicitly convert type 'Tridion.Extensions.Mediators.Razor.Models.KeywordModel' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)
Please help me.
If you get your output repeated for every character in a string, you are clearly iterating over the characters in the string and not the other range of values that you expected.
I quickly checked the relevant code of the Razor mediator and its ToString method indeed returns the Title of the underlying RepositoryLocalObject.
http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/AbstractRepositoryLocalObject.cs
http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/KeywordModel.cs
http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/DynamicItemFields.cs
The code that handles KeywordFields in in the DynamicItemsFields.cs file:
else if (itemField is KeywordField)
{
KeywordField keywordField = (KeywordField)itemField;
if (keywordField.Definition.MaxOccurs == 1)
if (keywordField.Value == null)
_dictionary[key] = null;
else
_dictionary[key] = new KeywordModel(_engine, keywordField.Value);
else
{
List<KeywordModel> keywords = new List<KeywordModel>();
int i = 0;
foreach (Keyword k in keywordField.Values)
{
var kw = new KeywordModel(_engine, k);
kw.Index = i++;
kw.IsLast = Index == keywordField.Values.Count - 1;
keywords.Add(kw);
}
_dictionary[key] = keywords;
}
}
So it looks like the myCategory property will either be a KeywordModel object (if the KeywordField is single-value) or a List<KeywordModel> (if the KeywordField is marked as multi-value in the Schema). Is your myCategory field single value? Or multi-value?
If it is single-value, what type of output were your expecting? If you were expecting the list of allowed values (instead of the currently selected value), check if you can access it through myCategory.Definition somehow (which should be a regular TOM.NET KeywordFieldDefinition object).