Combox first row not selectable - c++

How to make first row of combobox not-selectable? (https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.ComboBox?view=winrt-19041)

Combox first row not selectable
You could detect DropDownOpened event and find the fist item with ContainerFromIndex then disable it like the following. Because Combobox dropdown is lazy load, so we need add the task delay in DropDownOpened event.
private async void MyCb_DropDownOpened(object sender, object e)
{
await Task.Delay(100);
var item = MyCb.ContainerFromIndex(0) as ComboBoxItem;
if (item != null)
{
item.IsEnabled = false;
}
}

Related

Prevent combobox from being closed

How to prevent combobox from being closed (when user will try to select some item, the combobox will not close): https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.ComboBox?view=winrt-19041
You can subscribe the DropDownClosed event, when the drop-down list closes, this event will be triggered, you can set the IsDropDownOpen as true to open the drop-down list. In addition, you can declare a property to judge whether the user selects item to cause this event to be triggered. For example:
.xaml:
<ComboBox x:Name="MyComboBox" DropDownClosed="MyComboBox_DropDownClosed">
<ComboBoxItem Tapped="ComboBoxItem_Tapped">123</ComboBoxItem>
</ComboBox>
.h:
private:
bool IsSelected;
.cpp:
void AppCX::MainPage::MyComboBox_DropDownClosed(Platform::Object^ sender, Platform::Object^ e)
{
if (IsSelected == true) {
MyComboBox->IsDropDownOpen = true;
}
IsSelected = false;
}
void AppCX::MainPage::ComboBoxItem_Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
IsSelected = true;
}

How to get a reference to the list of a Flex List in Mouse Down event

I have a list in mxml. I need to show a menu when the user longpresses an item in the list. The menu will show some action on the item that has been pressed on.
I also have to make the pressed item the selected item in the list. So I need a reference to the list. I cannot find a normal way to get to the list so I did this:
var list:Object = event.currentTarget.parent.parent.parent.parent.parent
Which of course is hideous. I am looking for a better way to get a reference to the list.
Here is my code for the list:
<s:List id="catList" x="0" y="0" width="100%" height="100%" click="selectItemHandler(event)">
<s:itemRenderer>
<fx:Component>
<s:IconItemRenderer
styleName="labelFontStyle"
messageStyleName="descriptionFontStyle"
labelField="labelField"
messageField="descriptionField"
dataChange="onDataChange(event)"
mouseDown="onMouseDown(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function onMouseDown(event:MouseEvent):void
{
try
{
var tg:Object = event.target;
var selectedItem:Object = event.currentTarget.data;
if (selectedItem != null)
{
// Here I need to set the selectedItem property of
// the owning list.
// I don't know how to get to the list so I did this.
var list:Object = event.currentTarget.parent.parent.parent.parent.parent;
list.selectedItem = selectedItem;
}
} catch (e:Error) {}
}
]]>
</fx:Script>
</s:IconItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
I'm not sure but won't just set the selected property in the itemrenderer's onMouseDown do the trick ?
selected = true;
If not, check if this will get you your list:
var myList:List = owner as List;
Another approach would be to create a custom event that contains your item and fire it from the itemrenderer. Then listen for that event on the list and set the selectedItem property to the item you got in the event

Sitecore How to Get Control's Data Source Value

Is it possible to get __Rendering control's template field value on content item?
Especially, I'd like to get "Data Source" field value defined in control on page item, like below screenshot.
As shown in screenshot, I have some controls in page item and I'd like to get control's "Data Source" field value.
I used this code and I could list all controls using on the page item. But, I don't know how to get the control's browsed data-source information on the page.
public RenderingReference[] GetListOfSublayouts(string itemId, Item targetItem)
{
RenderingReference[] renderings = null;
if (Sitecore.Data.ID.IsID(itemId))
{
renderings = targetItem.Visualization.GetRenderings(Sitecore.Context.Device, true);
}
return renderings;
}
public List<RenderingItem> GetListOfDataSource(RenderingReference[] renderings)
{
List<RenderingItem> ListOfDataSource = new List<RenderingItem>();
foreach (RenderingReference rendering in renderings)
{
if (!String.IsNullOrEmpty(rendering.Settings.DataSource))
{
ListOfDataSource.Add(rendering.RenderingItem);
}
}
return ListOfDataSource;
}
RenderingReference[] renderings = GetListOfSublayouts(targetItem.ID.ToString(), targetItem);
List<RenderingItem> ListOfDataSource = GetListOfDataSource(renderings);
This is exactly what I wanted.
Perfectly working!!!!!!
public IEnumerable<string> GetDatasourceValue(Item targetItem)
{
List<string> uniqueDatasourceValues = new List<string>();
Sitecore.Layouts.RenderingReference[] renderings = GetListOfSublayouts(targetItem.ID.ToString(), targetItem);
foreach (var rendering in renderings)
{
if (!uniqueDatasourceValues.Contains(rendering.Settings.DataSource))
uniqueDatasourceValues.Add(rendering.Settings.DataSource);
}
return uniqueDatasourceValues;
}
}
Here is a blog post that can help: Using the Data Source Field with Sitecore Sublayouts
Here's the relevant code you can call from within a single control:
private Item _dataSource = null;
public Item DataSource
{
get
{
if (_dataSource == null)
if(Parent is Sublayout)
_dataSource = Sitecore.Context.Database.GetItem(((Sublayout)Parent).DataSource);
return _dataSource;
}
}
Accesing the DataSource property defined above will give you the item that is assigned as the Data Source from the CMS.

How do I access the parent item from a custom field in the Sitecore Content Editor?

Normally, when I want to access the current Item in Sitecore, I go through Sitecore.Context.Item. This works well when creating a tool which will be used by the end user, but not for a tool which is consumed by the Sitecore admins. If I want something to show up as a custom field in the Content Editor itself, the Context.Item is a reference to the Content Editor and not to the node which is selected in the editor.
For the most part I can get around this by using the ItemID property, but if I have event dispatchers on the field, those will no longer have access to the ItemID. Eg:
protected override void OnPreRender(EventArgs e)
{
if (IsEvent)
{
// ItemID is defined here!
Button live = FindControl(GetID(LiveButton)) as Button;
if (live != null)
{
live.ServerProperties["Click"] = string.Format("{0}.LiveClicked", ID);
}
}
}
public void LiveClicked()
{
// ItemID is blank here!
DoSomething();
}
How do I gain access to ItemID in my listener (like LiveClicked above)?
The way I solved it was through something called ServerProperties and I called the equivalent to this function in every listener.
private void SyncID()
{
var live = FindControl(GetID(LiveButton)) as Button;
if (live != null)
{
if(string.IsNullOrEmpty(ItemID))
{
ItemID = live.ServerProperties["owner_id"].ToString();
}
live.ServerProperties["owner_id"] = ItemID;
}
}

Infragistics UltraGrid (9.2) change a cell displayvalue without changing underlying datasource

I have a UltraGrid bound to a IList<MyDomainObject>. In MyDomainObject there is a field bool? isSomething. Problem is when this field is null the check-box in the cell is displayed as sort of a filled check-box, not as an unchecked check-box as my customer wants it. So in a InitializeRow-eventhandler I change the value of the cell in question to false if its value is null. But this also changes the underlying data in the MyDomainObject-object - which is not desirable.
How can I change the display-value of my field bool? isSomething without changing the value in the domain-object?
Thanks Vijay.
The style property of the column was set to Default. This produces a three-value checkbox style. By setting the style to a two-value checkbox null is displayed as false.
private readonly List<string> _nullableBoolColumns;
private void OnInitializeLayout(object sender, InitializeLayoutEventArgs e)
{
foreach (var band in e.Layout.Bands)
{
foreach (var column in band.Columns)
{
if(column.DataType == typeof(bool?))
{
_nullableBoolColumns.Add(column.Key);
}
}
}
}
private void OnInitializeRow(object sender, InitializeRowEventArgs e)
{
foreach (string column in _nullableBoolColumns)
{
e.Row.Cells[column].Style = ColumnStyle.CheckBox;
}
}