Linq2SQL and IQueryable - linq

Still new to LINQ2SQL so please forgive my ignorance ...
I have one user component which includes one Textbox and one button. The component is used as a generic ListOfValue Filter.
The component has one function to set a IQueryable which is passed to a form that is opened when the user clicks a button on the control.
The form consists of a grid (c1flexgrid) which is filled with the data from the IQueryable. There is a bindingsource on the form that gets the IQueryable as datasource.
The user can select inside the grid and after he selected an entry the dialog is closed and the selected row (or better the selected LINQ2SQL object from the row) is passed back to the control.
On this control i want to show one specific field out of that selected object. The name of that field is passed in to the user control as string.
My problem is, i don't know how to get that field data from an "generic" LINQ2SQL object.
In debugger i can see, that the selected object is of a specific enity type (corresponding to the query)
Probably somthing similar to
Workaround for lack of 'nameof' operator in C# for type-safe databinding?
but just the opposit way :)
Any help would be very welcome

I'm assuming in your IQueryable you don't know at design time the type T. If this is correct, you need to use reflection to get the value you want.
var value = typeof(T).GetProperty("MyField").GetValue(instance, null);
Alternatively, cast the instance to a common base type that implements your field.
CommonBase castInstance = (CommonBase)instance;
var value = castInstance.MyField;

Related

How to access to my Grid in Dynamic CRM365 View

I am working on Dynamic CRM365 plugin, in my entity view, I need to know which item has been selected, before I use DOM to detect, however, I can't pass the certification, because all DOM access are risk and need to be replaced, therefore, I checked Xrm.Page.getControl and Xrm.Page.ui.controls, but no luck.
I passed Xrm.Page.getControl("ssl_notesforsigns") or Xrm.Page.getControl("ssl_notesforsign") => return null
I call Xrm.Page.ui, ui = null.
Any idea how to get grid by code?
Thanks
It is good to hear that you no longer want to access the DOM. As you say, that is entirely unsupported.
What is the name of the subgrid on your form? If you go to a form editor and look at the properties for the subgrid, you will see the name (I am guessing that it is not called ssl_notesforsigns). This name is the one you should use, and it can be used when calling Xrm.Page.getControl("namehere") to get your grid context.
Xrm.Page has been deprecated (even though you can still use it). Instead, you should get a reference to your grid context through the execution context. See Client API grid context. For code executing on a form event, you can get your grid context through the form context as follows:
var formContext = executionContext.getFormContext(); // get the form Context
var gridContext = formContext.getControl("namehere"); // get the grid context
When you have a reference to your grid context, you can get the selected rows using getSelectedRows():
var allSelectedRows = gridContext.getGrid().getSelectedRows();

Syntax of Model Key Path - Bindings xcode 5.1.1

Hey I am new to mac development and I want to use bindings (xcode 5.1.1).
I want to set the Title of a radio button dynamically by an entry of an array controller. I am looking for something like a syntax description how I can perform it.
e.g. something like value1 WHERE value2="bla"
If I trying to search at google I always find solutions which did it programmatically.
Is there anywhere some examples which show me the syntax I can use in this field?
The picture below should you show what I mean.
Answering the question as clarified in the comments…
First, bindings is not always the right technology. It can simplify some things, but it can't do everything and even for some of the things that it can do, it doesn't necessarily make them simpler.
Radio buttons are often organized in an NSMatrix. In that case, you can bind the matrix bindings to track the selection. There are three content-related bindings for a matrix, which can be kind of confusing. The "content" binding is the base. In some cases, it's sufficient. However, if there's a distinction between the object being bound and the value that should be shown by the cells of the matrix, then you can bind the "contentValues" binding to be a subpath of the content binding. That is, it needs to be the same as the content binding with possibly additional elements added to the end of the model key path.
Furthermore, if you want the selected object to be distinct from the content object, you can bind "contentObjects" to a subpath of the content binding.
For example, there may be an array controller whose content is a bunch of Person objects. The matrix content binding might be bound to that array controller's arrangedObjects. If you leave it like that, the cells of the matrix will be populated from the description of each Person object. However, you could bind the matrix's contentValues to the array controller, arrangedObjects, model key path fullName. Then, the matrix cells will be populated with the full name of each Person object.
If you then bind the matrix's selectedObject binding to a property on your window controller, that property will be set to the selected Person object each time the matrix selection changes. If you would prefer, you could bind the matrix's contentObjects binding to the array controller, arrangedObjects, model key path uniqueID. In that case, the window controller property would not be set to the selected Person object itself, but to its uniqueID property.
Alternatively, you could bind the matrix's selectedIndex binding to a controller property. If you use the window controller, then that just directly sets a property on the window controller to indicate the index of the matrix's selection. Or you could bind it to the array controller's selectedIndex property, in which case the selection is "stored" in the array controller.
You need a keypath that takes no parameter as described in the key-value coding (KVC) reference.
By binding to an array controller's selection, if the selection collection is one object with a property or method "value1," then the binding runtime is calling the method valueForKeyPath:#"value1".
The NSObject protocol has performSelector:withObject, but there is nothing like valueForKeyPath:withObject in the KVC protocol or the NSKeyValueBindingCreation protocol
That said, registering dependent keypaths can provide some equivalent behavior...
+ (NSSet*) keyPathsForValuesAffectingValue1
{
return [NSSet setWithObjects:#"value2",nil];
}
... and that would ensure that any time value2 changes, the binding to value1 is re-evaluated.

Is it possible to customize a CRM 2011 (online) entity view?

CRM 2011 online. I have a requirement to color code entries that appear in an entity view. On a form for entity A is a field that is a lookup to entity B. Entity B has > 1 views defined for it. The lookup field on form A defines what view of entity B appears when the lookup button is pressed. I have been asked if the view that appears can show the records such that the entries are color coded based on a column value of the view e.g. if a record in the view has a value of X for a particular column, show that record with a green background, else show with a red. The view in question is a "public" view and is unmanaged and customizable.
In effect what I am asking is if it's possible to manipulate the display of that view somehow? If not, is the only other option to override the clicking of the lookup on the form for entity A and display my own custom view window?
What I have found in my searching is this which seems to suggest that I can export a view and manipulate the XML to incorporate some kind of conditional formatting. However, all it tells me is that the value is a string. Anyone have any experience there?
You are going to make it harder on yourself by having unmanaged code in your solution.
That being said, you can easily do this sort of thing in an iFrame or Silverlight control.
A quick google brought up some examples on how to do this.

Setting a default selection for an NSPopupButton?

Is it possible to set a default selection on an NSPopupButton? I have one that allows the user to select the type of server they want to set up, but since an NSPopupButton always shows the first item, they may ignore it if that's the type they want. However, even though that item is being displayed, calling -selectedItem returns (null). Everything works fine if the user picks an item from the menu first.
The Button's content and contentValues are bound to the same Array Controller, which in turn is bound to the keys property of an NSDictionary. I've tried binding the selectedIndex to a variable in the controller and updating that in code, but it has no effect. (I may just be binding it wrong...) How can I select the first item by default?
Thanks in advance!
SphereCat1
When using Bindings, you don't need to and shouldn't get any model info—neither the model itself nor selection state—from the views directly. Talk to the controller that owns the model and the selected indexes.
Note that “index” doesn't have any meaning for an NSDictionary, and keys is not a property of an NSDictionary. (Indeed, I would not be surprised if you were to get an exception because your dictionary does not have an object for the key “keys” in it.) It is a method, and not the accessor kind, so while you can ask the dictionary for the value of that method using Key-Value Coding, you should not.
What you should do is make model objects representing the server types, and hold an array of those, and bind the array controller's content to the property whose value is that array. Bind the pop-up button's contentValues to a name property of your model objects, which should hold the localized name of each server type.

Get NSComboBox to work like an HTML Combo

Is it possible to have the values displayed in an NSComboBox be different from what is retrieved with objectValueOfSelectedItem?
So, it will display an object's string name but it's int recordId is returned instead of the string name? Other than using selected index and getting it from the source array, of course...
Are you looking for NSPopUpButton? It's more similar to an HTML <select>. An NSComboBox lets users directly type in new values, as well as pick them from a list, but you can't do that with plain HTML.
In any event, you should be able to give either control a bunch of custom objects that have a recordid property, and then retrieve the selection using [[comboBox objectValueOfSelectedItem] recordid]. You'll also need to write a custom formatter for these objects.
PopupButton is it.
objectValueOfSelectedItem wont work for me since it returns what is displayed and I want a string displayed but int returned.

Resources