grid binding to a listbox selecteditem runtime - listbox

I am a beginner, so please bear with me.
Let's say we have a listbox and a grid that contains textblocks on a window. But these are instanced from separate xaml files, and added to two different stackpanels in the window.
How can I bind the grid datasource to the listbox's selected item in runtime?
I guess what I need to do is to do this following xaml in runtime:
Grid DataContext="{Binding ElementName=lstContacts, Path=SelectedItem}"
Thanks.

You could handle the Window's Loaded event, and in your handler: traverse your Window's children using VisualTreeHelper to find your ListBox based on its name, then set your Grid's DataContext.
Here is a question that discusses, and provides a method for, finding children in such a manner.

Related

Selection contains a component introduced in an ancestor

Is it possible delete or add new component inside free embracadero theme?
What is ancestor?
Ancestor, in this context, means a class in the chain of classes from wich the object under discussion inherits. For example look at TButton in help. At the top of the help page, all ancestors of TButton are shown as a chain of classes starting with TObject
Thus, the error message means that an ancestor class (ancestor of your selection) has declared the component you try to delete.
If your version of Delphi comes with style files, you may modify them. I would copy the original style file to a safe place.
Note, that the structure view, left top of IDE, shows a different hierarchy that shouldn't be mixed with the class hierarchy. The parent - child chain (structure) indicates the components that hosts other components. E.g. A form can be a parent to a panel which might be the parent of a button. Or a grid panel that has collections of other components.
I found that if you change the View: drop-down menu to Master you can delete the selected component(s).
You have to switch to the Master View in order to delete components you dropped on the form.
Go to View: Master
You have to switch to the Master View

(delphi) how to add property to child controls?

In the Delphi IDE, some components in Delphi have the ability to "add" properties to the child controls they contain in the property editor.
How can I achieve the same thing with my own TCustomPanel descendant?
Some more details:
What I want to achieve is the following: I have a very complex configuration dialog for an application with a large number of visual components.
I want to add to each of these components a "complexity index" (an integer) that will be used to show or hide the component based on a selection made by the user (a dropdown with "simple", "advanced" and "expert" options).
I understand that the property will actually belong to the parent panel but I need a way to display it, in the IDE, as if it was attached to the control it is related to.
The perfect exemples are the various "organizational" panels provided by Delphi: TGridPanel and TRelativePanel. Each of these have a ControlCollection (published) properties that is used to hold the actual states of the additional properties but I failed to locate how the property editor knows that it must attach the properties to the child controls.
Here is a screenshot of a TLabel placed inside a TRelativePanel with the relevant properties highlighted:

how to add bootstrap grid in side of my main RTE in umbraco?

I have a Document Type which has a main content box (RTE). now I wand add a grid layout inside it and add "Partial View Macro" to this grid cells.
for example create a 1*3 grid and add a summery card inside of each cell. like this view :
in this case I implement card as a "Partial View Macro"
You should be able to create a macro that can point to a separate node that contains a Grid Layout property and similar to a template calling the GetGridHtml() extension method, you can call it from your macro code like this:
Html.GetGridHtml(gridNode, "gridLayourPropertyName");
Where gridNode is an IPublishedContent object that your macro can have as a parameter, and "gridLayourPropertyName" is the Grid Layout property of that node.
I haven't used this technique using a Macro from a RTE, but I've done something similar to build a grid within another grid layout. This may not be the best technique to follow and I'd strongly recommend looking into replacing the RTE property with a grid layout. You can use RTE as a grid editor, so you could migrate your existing property data and then you will have all the flexibility to create/configure/customize grid editors using current best practices to meet your requirements.

Can I use Delphi LiveBindings to create a two-column 'Name','Value' editable list from a TObjectBindSourceAdapter?

Using Delphi XE7 and FireMonkey I am looking at simple ways of displaying (and editing) some object property values in a TGrid. I have followed the tutorial showing how to bind TGrid columns to object properties and using a TObjectBindSourceAdapter I have a neat, single row grid populated from my one object as they show in the example.
However, I will only ever have one object in the grid (a single row) so I would really like to turn my grid data through 90 degrees to give me two columns - a fixed 'Name' and an editable 'Value'. My object properties would then be listed vertically (effectively like the Object Inspector view).
Is there a LiveBindings way of doing this, or should I use another control such a TListView? I'm new to LiveBindings!
Thanks for any suggestions.

how to set the tabwidth of the listbox portion of a TComboBox in Delphi

You can easily achieve a multicolumn effect in a listbox by setting the TabWidth property of TListbox. For example, http://delphi.about.com/cs/adptips2000/a/bltip1200_3.htm
I need to do the same in the drop down list of a ComboBox, but comboboxes don't publish any TabWidth property.
Any ideas?
In a comment to this answer advising you to owner-draw the list box items you say:
I'm wondering why I must do that when the required functionality already exists on a listbox
A combo box is actually composed of three native child windows - the combo box itself, an embedded edit, and a list box. You can use the GetComboBoxInfo() function to fill a COMBOBOXINFO structure (i.e. a TComboBoxInfo record) with information about the control, and it will return the 3 HWND elements in it. With that you are able to alter the appearance and behaviour of the list box. In principle.
For the list box to use the tab stops it needs to have the LBS_USETABSTOPS style flag set. Unfortunately this can't be turned on later, the list box has to be created with it. So you could use the functionality only if you were able to turn the style flag on for the list box, which is created during the CreateWindowEx() call for the combo box. AFAICS this can only be done by hooking the CreateWindowEx() call itself, identifying the internal call that creates the list box, and altering the passed style. This means runtime modification of code, and not in your executable but in a Windows DLL.
Owner-drawing the list items looks like it would be much easier.
From what I know there is not so simple way as TabWidth here but you can override Paint method and draw it yourself. Looking at listbox and combobox sources may help.

Resources