I want to display the selected value from the comboBox into a label.
<xp:label id="label4">
<xp:this.value><![CDATA[#{javascript:var componenta = Contr.getItemValueString("txt_tipcontractcv");
if (componenta == "")
{ return "void";}
if (componenta !="")
{ return "My value is "+componenta}}]]></xp:this.value>
</xp:label>
The label is on a panel, and I did a partial refresh to the respective panel.
My comboBox is binded to a data element.
label4 is always void. Why?
Thank you,
Florin
I changed code into:
var componenta = getComponent("combo").getValue();
if ((componenta == null) || (null == componenta))
{ return "void";}
else if ((componenta != null) || (null != componenta))
{ return "My value is "+componenta}
and now it returns : My value is
It seems that componenta is an empty string. Why?
Try Contr.getValue("txt_tipcontractcv") (assuming that Contr is your datasource).
The reason is the value selected is not sent to the server.
Could you give us the code for combobox, and panel with label. It will give us clear idea for the cause
Are you using partial execution mode?
Is combo box bind to data source value="Contr.txt_tipcontractcv"?
You may also code the label as below, if that suits
<xp:label id="label4" value="Contr.txt_tipcontractcv" />
Related
Problem: When I select a check box (in Column '1'), the OnSelection event should find a Label on Column '0' in the same Row, but I am getting:
System.InvalidCastException: 'Unable to cast object of type 'System.Windows.Controls.CheckBox' to type 'System.Windows.Controls.Label'.'
I am initializing the view as such:
Label lbName = new() { Content = "labelName" };
Grid.SetColumn(lbName, 0);
GrWindow.Children.Add(lbName);
CheckBox ckSelection = new();
ckSelection.Checked += OnSelection;
Grid.SetColumn(ckSelection, 1);
GrWindow.Children.Add(ckSelection);
And on the OnSelection method, where the exception is triggered:
string? labelName = GrWindow.Children.
Cast<Label>().
First(e => Grid.GetRow(e) == row && Grid.GetColumn(e) == 0).
Content as string;
In other place in my app, I am using a very similar approach to get a name from Row '0' and works fine.
There is only one children on every row/column = '0', and its a label, I dont know how to debug such situations, since the checkbox is on column='1'.
Thanks in advance.
Replace
.Cast<Label>()
with
.OfType<Label>()
to get only the Labels.
Otherwise you are trying to cast all child elements to Label, which will of course fail for the CheckBox.
An alternative to querying the Children collection might be to assign the associated Label to the Tag property of the CheckBox
ckSelection.Tag = lblName;
and get it back in the event handler by
var checkBox = (CheckBox)sender;
val label = (Label)checkBox.Tag;
i want to get the value of CheckBoxColumn in DataGrid wpf
i try this code
foreach (spShowTotal_Result item in dgShowStudent.ItemsSource)
{
if (item.boolCol == true)
{
MessageBox.Show("fail");
}
else
{
MessageBox.Show("success");
}
}
but don't take the changed value but take the same value of the my ItemsSource .
i try this code
foreach (spShowTotal_Result item in dgShowStudent.ItemsSource) { bool? check = ((CheckBox)dgShowStudent.Columns[0].GetCellContent(item)).IsChecked; }
but this error is appear Unable to cast object of type 'System.Windows.Controls.ContentPresenter' to type 'System.Windows.Controls.CheckBox'.
I have two felds in my dialog, one is text field(leftpadding) and another is dropdown with four options(option 1, option 2, option 3, option 4).My requirement is to display/enable the textfiled when the user selects option 3 and option 4 only.
I added listeners(selectionchanged) node to the dropdown field. loadcontent event is firing but selectionchanged is not working fine. Please find below for the code snippet
selectionchanged:
function(field,value){
var layoutoption = "";
layoutoption = field.findParentByType('dialog').form.findField('./footerstyle').getValue();
alert('layoutoption :'+layoutoption);
if(layoutoption =='3' || layoutoption =='4'){
field.findParentByType('dialog').form.findField('./leftPadding').enable(this);
}else {
field.findParentByType('dialog').form.findField('./leftPadding').disable(this);
}}
If you look at the CQ.form.Selection API, you would find that when the selectionchanged event is fired, the following arguments would be passed to the listener.
this : The selection field
value : The raw value of the selected field
isChecked : true / false, used when the selection is of type checkbox.
Thus, you could modify your listener as shown below.
function(field, value) {
var dlg = field.findParentByType('dialog');
// the value holds the value of the selection
if(value =='3' || value =='4'){
// getField() of the dialog class returns the field with the given name
dlg.getField('./leftPadding').show();
}else {
dlg.getField('./leftPadding').hide();
}
}
The getField() method of the CQ.Dialog returns the field with the given name. In case more than one field with the same name exists, it returns an array of those fields. You can then show() or hide() the fields based on your requirements.
EDIT :
CQ 5.4 somehow doesn't remove the entire widget, instead removes only the input field leaving behind the Field Label, Description etc.
In such cases the following function may be used.
function(field, value) {
var dlg = field.findParentByType('dialog');
if(value == '3' || value == '4') {
dlg.getField('./leftPadding').el.parent('.x-form-item').show();
}
else {
dlg.getField('./leftPadding').el.parent('.x-form-item').hide();
}
}
I've read all the similiar posts about this darn control (DataGridViewComboBoxCell) and setting it's value programmatically but implementing all the suggestions hasn't worked. I could probably change the UI to get around this problem but I don't like to be beat!
private void PopulateAreaForRoleAssociation()
{
// If businessRoleList is null then no data has been bound to the dgv so return
if (businessRoleList == null)
return;
// Ensure businessArea repository is instantiated
if (businessAreaRepository == null)
businessAreaRepository = new BusinessAreaRespository();
// Get a reference to the combobox column of the dgv
DataGridViewComboBoxColumn comboBoxBusinessAreaColumn = (DataGridViewComboBoxColumn)dgvBusinessRole.Columns["BusinessArea"];
// Set Datasource properties to fill combobox
comboBoxBusinessAreaColumn.DisplayMember = "Name";
comboBoxBusinessAreaColumn.ValueMember = "Id";
comboBoxBusinessAreaColumn.ValueType = typeof(Guid);
// Fill combobox with businessarea objects from list out of repository
comboBoxBusinessAreaColumn.DataSource = businessAreaRepository.GetAll();
// loop through the businessRoles list which the dgv is bound to and get out each dgv row based upon the current id in the loop
businessRoleList.Cast<BusinessRole>().ToList().ForEach(delegate(BusinessRole currentRole)
{
DataGridViewRow currentRowForRole = dgvBusinessRole.Rows.Cast<DataGridViewRow>().ToList().Find(row => ((BusinessRole)row.DataBoundItem).Id == currentRole.Id);
// Get a reference to the comboBox cell in the current row
DataGridViewComboBoxCell comboBoxCell = (DataGridViewComboBoxCell)currentRowForRole.Cells[2];
// Not sure if this is necessary since these properties should be inherited from the combobox column properties
comboBoxCell.DisplayMember = "Name";
comboBoxCell.ValueMember = "Id";
comboBoxCell.ValueType = typeof(Guid);
// Get the business area for the current business role
BusinessArea currentAreaForRole = businessAreaRepository.FetchByRoleId(currentRole.Id);
// if the role has an associated area then set the value of the cell to be the appropriate item in the combobox
// and update the cell value
if (currentAreaForRole != null)
{
foreach (BusinessArea area in comboBoxCell.Items)
{
if (currentAreaForRole.Id == area.Id)
{
comboBoxCell.Value = area.Id;
dgvBusinessRole.UpdateCellValue(2, comboBoxCell.RowIndex);
}
}
}
});
}
The dgv is first bound to a binding list holding BusinessRole objects, then the combobox column is bound to a basic list of BusinessArea objects that come out of a repository class. I then loop through the bindinglist and pull out the row of the dgv that is bound to the current item in the bindinglist loop.
With that row I make a database call to see if the BusinessRole entity is associated with a BusinessArea entity. If it is then I want to select the item in the combobox column that holds the BusinessAreas.
The problem is that when the grid is loaded, all the data is there and the comboboxes are populated with a list of available areas, however any values that are set are not displayed. The code that sets the value is definately getting hit and the value I am setting definately exists in the list.
There are no data errors, nothing. It's just refusing to update the UI with the value I programmatically set.
Any help would be greatly appreciated as always.
Thanks
This code works for my first combo box I have in my row with the following code, but I try it with the next one in the row and it doesn't work. I could use the help with the rest I have 3 more to do. I do set the combo boxes on a second form from this form with the same code as is on the last line of the try block but using the cell information instead of the dataset
try
{
string strQuery = "select fundCode from vwDefaultItems where IncomeType = '" + stIncome + "'";
SqlDataAdapter daDefault = new SqlDataAdapter(strQuery, conn);
DataSet dsDefault = new DataSet();
daDefault.Fill(dsDefault);
strDefFund = dsDefault.Tables[0].Rows[0].ItemArray[0].ToString();
dgvCheckEntry.Rows[curRow].Cells[7].Value = dsDefault.Tables[0].Rows[0].ItemArray[0].ToString();
}
catch (Exception eq)
{
}
I am developing a program which gets all Clearcase regions (basically strings) & adds them to Combo box. I compare an existing clearcase region string in newly added items in combo box & if it is found then I want to select it, but because nothing is selected for the first time, selectedItem is null & selectedIndex = -1.
when I assign 0 to selectedIndex, error comes --> object not set to instance of an object!! same problem when you assign something to selectedItem; gives an error.
whats wrong with my code?
private void PopulateClearCaseRegionComboBox ( )
{
clearCaseRegionComboBox.Items.Clear();
foreach ( Match token in RegularExpression.Match( "\\w+", clearTool.CmdExec( "lsregion" ) ) )
{
clearCaseRegionComboBox.Items.Add(token.Value.Trim());
if (clearCaseRegion.ToUpperInvariant() == token.Value.Trim().ToUpperInvariant())
{
clearCaseRegionComboBox.SelectedIndex = clearCaseRegionComboBox.Items.IndexOf(token.Value.Trim());
}
}
clearCaseRegionComboBox.Sorted = true;
}
A notification: the SelectedIndexChanged event also occurs when you set SelectedIndex or SelectedItem. So if you have something there, check it out also. :) I've passed several hours on it, because you don't see it while debugging.
Are you sure the following line returns a valid index?
clearCaseRegionComboBox.Items.IndexOf(token.Value.Trim());
The Add method returns the index of the newly added item. You can use that value inside your if statement.
private void PopulateClearCaseRegionComboBox ( )
{
clearCaseRegionComboBox.Items.Clear();
foreach ( Match token in RegularExpression.Match( "\\w+", clearTool.CmdExec( "lsregion" ) ) )
{
int index = clearCaseRegionComboBox.Items.Add(token.Value.Trim());
if (clearCaseRegion.ToUpperInvariant() == token.Value.Trim().ToUpperInvariant())
{
clearCaseRegionComboBox.SelectedIndex = index;
}
}
clearCaseRegionComboBox.Sorted = true;
}
Perhaps you can reveal more of your code in context? I say this because it would seem impossible to get this error at this point in your representative code. You've already used the object to add an item 3 lines up.
Are you sinked to any events on the combo box that would assign the clearCaseRegionComboBox variable to null?