How to make WPF ComboBox default selection to blank - wpf-controls

I have an enum like:
enum Gender
{
Male = 1,
Female = 2
}
Then I have a Combobox binding to a list of Gender.
<ComboBox ItemSource = 'Binding GenderList, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged'
SelectItem = 'Binding SelectedGender' />
When user opens the view, how can I make ComboBox selection default to blank? Then after user made a selection, the blank selection is removed from the ComboBox source.
Thanks
Thanks all the replies. I fixed my problem by manully assigning the selected item to null.

What you are describing is the default behavior of the ComboBox. You don't need to do anything (except for correct the typos in your XAML. It should look like:
<ComboBox ItemsSource="{Binding GenderList}" SelectedItem="{Binding Path=SelectedGender}" ></ComboBox>

Related

MFC ComboBox dropdown list too short

I have dropped ComboBox on dialog form. Also I have added some text to it:
BOOL CMyAppDlg::OnInitDialog()
{
CComboBox *combo= (CComboBox *)GetDlgItem(IDC_COMBO_TT);
combo->AddString("s1");
combo->AddString("s2");
//...
return TRUE;
}
When I drop down ComboBox it shows only one selection line and adds arrows to select other items. How to increase dropdown size?
Click the combo button in dialog editor. You can now drag down to set the open size.

How to get the Telerik RadGrid footer row value?

Using C#, how do I get values from a textbox which is in a RadGrid Footer?
I am getting an error in the following code. How do I solve it?
TextBox texte=(TextBox)RadGrid1.FooterRow.FindControl("textempno");
You should do it like this:
if (e.Item is GridFooterItem)
{
TextBox texte = (TextBox)RadGrid1.FooterRow.FindControl("textempno");
}
Also, you can do it like this:
GridFooterItem footerItem = (GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
TextBox texte=(TextBox)footerItem.FindControl("textboxid");//accessing Button inside FooterTemplate
I have give the index [0] while getting the grid footer item as the text box is the one and only item in my grid footer. If you have multiple footer items, you can give the index of the item you want to find.

how to preserve listview selected/ clicked item color while scrolling?

this is really a strange problem i came across several google searches which returned in vain .
Well i have a list view in which the selected item color should be changed while user click on the item.
This post helped me to change the list view selected item color. Now i am able to change the color while the item is clicked . But if i scroll the list view the color jumps out of selection.
https://stackoverflow.com/a/12080202/1657093
If a item is selected say for instance the listview item on first row the last item is also gets selected while scrolling the item color keeps on moving to the item which i never selected.
here is the list view
<ListView
android:id="#+id/loadedlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/horizontalScroll"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Title"
android:layout_toLeftOf="#+id/sidepanel"
android:scrollingCache="false">
</ListView>
I use array adapter to populate the list view
ringlist.setAdapter(new ArrayAdapter
(this,android.R.layout.simple_list_item_1,rings));
and use list view's on click method to set the color ,
ringlist.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int pos,long id) {
// TODO Auto-generated method stub
try{
String con;
String s = ringlist.getItemAtPosition(pos).toString();
con = s.toLowerCase();
String selectedFromList = con;
int resId = getResources().getIdentifier(selectedFromList, "raw",
"com.example.android");
}
if (row != null) {
row.setBackgroundColor(Color.BLACK);
}
row = view;
view.setBackgroundColor(Color.GREEN);
}
}
});
the above code does the job but while scrolling the list something goes wrong
please advice.
This is common issue of Listview in android.
When we use checkbox/radio button in Listview Item after scrolling down or up, the selected position does gets changed at some different places.
The only solution to this till now is, we need to maintain the selected position in a arraylist(or to any structure you are comfortable).
And as you scroll up/down the list view, the getview does gets called.
So write code in your getview() to make checkbox items selected from arraylist.
Also dont use if-else condition in getview for convertview.
Store clicked/selected positions in a set or array in your onItemClick() method. Write code to show clicked/selected items in getview() method of your adapter using stored positions.

ExtJs layout + Window

While adding component dynamically, 'this.container is null' is displayed in firebug.
I have a window with some combo boxes say combo1, combo2, combo3 and a label. Based on the selection value of combo3 the 'label' field is removed and replaced with combobox or text field. i do this my using
form.items.removeAt(4);
form.items.insert(4, newItem); #here newItem can be combox/textfield
form.doLayout();
The form resides inside a panel.
When above lines are execueted. 'this.container is null' is displayed and component fails to insert/add in appropiate position.
Any suggestions?
You should not be modifying the underlying items collection. Use the remove/insert methods on the container.
Try to comment those lines line-by-line to see which one produces error like
form.items.removeAt(4);
//form.items.insert(4, newItem); #here newItem can be combox/textfield
//form.doLayout();
form.items.removeAt(4);
form.items.insert(4, newItem); #here newItem can be combox/textfield
//form.doLayout();
form.items.removeAt(4);
form.items.insert(4, newItem); #here newItem can be combox/textfield
form.doLayout();
Your problem could take place because of inserted/replaced object is no yet prepared when you try to insert it. Give us your newItem initilization code.
Upd
Or you can wrap your changing components (label, combobox, textfields) in a panel with card layout. And on change of combo3 simply select exact card in that panel.

C# TableLayoutPanel replace control?

I was wondering if it was possible to replace one control in a TableLayoutPanel with another at runtime. I have a combo box and a button which are dynamically added to the TableLayoutPanel at runtime, and when the user selects an item in the combo box and hits the button, I'd like to replace the combobox with a label containing the text of the selected combo box item.
Basically, if I could simply remove the control and insert another at it's index, that would work for me. However I don't see an option like "splice" or "insert" on the Controls collection of the TableLayoutPanel, and I was wondering if there was a simple way to insert a control at a specific index. Thanks in advance.
Fixed this by populating a panel with the two controls I wanted to swap and putting that into the TableLayoutPanel. Then I set their visibility according to which I wanted to see at what time.
This is what I've been able to come up with for what I needed. It gets the position of the ComboBox and makes a new label using the selected value.
// Replaces a drop down menu with a label of the same value
private void lockDropMenu(ComboBox dropControl)
{
TableLayoutPanelCellPosition pos = myTable.GetCellPosition(dropControl);
Label lblValue = new Label();
myTable.Controls.Remove(dropControl);
if (dropControl.SelectedItem != null)
{
lblValue.Text = dropControl.SelectedItem.ToString();
lblValue.Font = lblValue.Font = dropControl.Font;
// Just my preferred formatting
lblValue.AutoSize = true;
lblValue.Dock = System.Windows.Forms.DockStyle.Fill;
lblValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
myTable.Controls.Add(lblValue, pos.Column, pos.Row);
}
}

Resources