Get ComboBoxItem from Combobox - winrt-xaml

In my universal windows Application I have below "xaml" :
<ComboBox Margin="8" Header="Language" x:Name="cmbLanguage" x:Uid="cmbLanguage" ItemsSource="{x:Bind Languages}" SelectionChanged="LanguageComboBox_SelectionChanged"/>
Now i need to iterate through my combobox and get the combobox items to disable some of them. How can i get access to the items from code behind?

Now i need to iterate through my combobox and get the combobox items to disable some of them. How can i get access to the items from code behind?
You could get ComboBoxItem with ContainerFromIndex method, and the set IsEnabled property to false or true, for more you could refer to the follow.
ComboBoxItem^ item = dynamic_cast<ComboBoxItem^>(cmbLanguage->ContainerFromIndex(CurrenIndex));
item->IsEnabled = false;

Related

Powerapps Visible function

For some reason the Visible function in my Powerapps won't work I just wrote in OnSelect() Mail.Visible = false
The Mail is in this case a Textinput/ TextBox.
When I click on the button nothing happens. I can't find a documentation about it on the MS Website but I have in Powerapps a fuction called "Visible"
You need to create a variable in the button's (or another control) OnSelect property:
UpdateContext({ mailVisible: false })
And set the Visible property of the Mail control to mailVisible. You may need to initialize that variable to true, for example, in the screen's OnVisible property:
UpdateContext({ mailVisible: true })
PowerApps works similarly to Excel - you cannot, by an action, change directly the value of a cell (e.g., A1 = 42). But you can make the A1 cell reference another cell (say, =A4), so when you change the value of the cell A4, A1 will be updated as well. The same principle applies in PowerApps - you cannot change the value of a property from an action, but you can update the value that the property references.
Credit #SeaDude
This worked perfectly for me toggling the variable back and forth to show/hide a few layers.
Set(mailVisible, !mailVisible)
So I have a few items like this. I'm not sure if this is the BEST way but I know it works.
Set a variable on the app start:
App = Set(variable_visable, "");
Button code:
Onselect = Set(variable_visable.,"1");
Item that you want visible:
Visibility = If(variable_visable="1", true, false);
Edit: You can reset your variable at any point to hide that section.
Sometimes power apps fights you on things that seem correct.
The Visible will the condition that is true to make it show.
For example
If I have one TextBox named TextInput1 and I want a control to be visible when the Text entered = true it will be. For this example use a label.
Label1's visible function will be TextInput1.Text = "true"
This will show when the input text will be true. if it's false or anything else the label won't show. This is a very basic use of the visible but can be used in many ways.
In On select property of button you can't set any other control property directly.
you need to follow the steps as:
1- you need to set a boolean type variable on OnSelect of button e.g.
Set(varShowMail,false)
2- go to TextInput Mail and select its Visible property and assign the variable "varShowMail"
It will work 100%.
Set on visible of screen property UpdateContext({ Var_Visible: false})
set a variable on control "select" or "change" to true"UpdateContext({ Var_Visible: true})" and use the variable in other control visible property that you want to show or hide, if required you can use condition to set a variable to true or false

How to access a FormControl checkbox in an Excel sheet using OpenXML SDK

I have a spreadsheet that has a number of check boxes in various cells on the sheet that I need to get the value of (checked/unchecked) from within a c# program.
I'm using the OpenXML SDK v2.5 and the associated toolbox.
Using the toolbox I can see the check box controls as part of the AlternateControlParts collection. These are not ActiveX checkboxes but are form controls added via the developer tab in Excel.
When I use the SDK I can also see the WorkSheetPart which has a ControlPropertiesParts collection on it which lists all the checkboxes.
My problem is, how do I find which checkbox is in which cell or at least related to which cell?
I have also found the collection
wsPart.ControlPropertiesParts.First().DrawingsPart
.WorkSheetDrawing.DrawingsPart.WorkSheetDrawing
This collection appears to have the alternate content of each of the checkboxes and if I drill down further I can find the anchor points which appear to give the location of the checkboxes relative to the cells on the sheet. However, the col and row Id’s don’t appear to exactly match up and I suspect that the Offset values may also have something to do with it.
If someone can point me in the right direction on how to map the checkboxes to the correct row/cells I would be very grateful.
Thank you for any help.
Regards
Paul
I have a solution, it contains only the logic (The property FormControlProperties is available since Office 2010:
SpreadsheetDocument document;
string sheetName = "sheetName";
string controlName = "Option Button 5";
...
var wbPart = document.WorkbookPart;
var theSheet = wbPart.Workbook.Descendants<Sheet>().FirstOrDefault(s => s.Name == sheetName);
var wsPart = (WorksheetPart)wbPart.GetPartById(theSheet.Id);
var control = wsPart.Worksheet.Descendants<DocumentFormat.OpenXml.Spreadsheet.Control>().FirstOrDefault(c => c.Name == controlName);
var controlProperies = (ControlPropertiesPart)wsPart.GetPartById(control.Id);
bool isChecked = controlProperies.FormControlProperties.Checked == "Checked";
But it is simplier to map the FormControl value to a cell and read the cell value if the you can edit the excel file.

Enable Command Buttons based on Combobox

I have a userform that needs to display different options based on the user that is opening the form. Some of these options should only be enabled once a selection has been made in a combobox, but I can't seem to find a way to get them to update after a combobox selection is chosen.
What I'm using is:
Private Sub cbCharts_AfterUpdate()
If Me.cbCharts Is "" Then
Me.bQuickEntry.Enabled = False
Me.bView.Enabled = False
Exit Sub
ElseIf UserDep = "Quality Control" Then
Me.bQuickEntry.Enabled = True
Me.bView.Enabled = True
Me.bAdjust.Enabled = True
Else
Me.bView.Enabled = True
Me.bQuickEntry.Enabled = True
End If
End Sub
Where cbCharts is the combobox in question, and bQuickentry, bView and bAdjust are the buttons.
Using this code, the buttons don't enable until I click somewhere else on the form, instead of immediately after making the selection. Then, if I clear the combobox Excel hangs and has to be force closed.
I've tried instead using Private Sub cbCharts_OnExit with the same code, but it doesn't do anything at all.
I know I can just leave all the buttons enabled and visible add a verification step to the code for each button to ensure that there is a valid combobox selection before proceeding, but I would prefer to enable and set their visibility to prevent user confusion, as some of these buttons will not be usable by the majority of spreadsheet users.
What am I doing wrong?
Try putting your code into the cbCharts_Click() event function instead. This event is fired as soon as the user selects an item in the list.

c# listbox i have trouble with

I created a list in a button ADD:
{
List <string> Names = new List<string>();
Names.Add(textBox1.Text);
textBox1.Text = " ";
}
I created another button SHOW NAMES and i want these names I entered in the list, to be listed in the listbox? How can this be done?
First, you need to move that first line outside of the button click method, because if you declare the list inside the method, it will be gone once that method returns.
For your SHOW NAMES method, if all you want to do is display the list, you could use a TextBlock instead of a listbox, and it will be a little easier:
TextBlock tb = new TextBlock();
tb.text = string.Concat(Names);

Is it possible to create OptionButton Switch Effect?

Something like this:
Private Sub opt01_Click()
If opt01.Value = True Then
opt01.Value = False
Else
opt01.Value = True
End If
It would be suitable for my formDesign, instead of looking for and importing some similar small picture.
Because an OptionButton's value is always true when the Click event runs, you will need to store its desired value in a variable. Here is an example using a Form Control Option Button within a sheet named Option Button 1 on sheet 1. This method is stored in a module.
Private optionClicked As Boolean
Sub OptionButton1_Click()
Dim o As OptionButton
Set o = Sheets(1).Shapes("Option Button 1").OLEFormat.Object
o.Value = Not optionClicked
optionClicked = Not optionClicked
End Sub
Note however, that using this method, that clicking on any option button will make all other option buttons false. So to use multiple option buttons as check boxes, you will need to store the correct value of the option buttons (probably in an array)... and correct the values every time any option button is clicked.
Are you sure you can't use check boxes?

Resources