combobox interview questions
Top combobox frequently asked interview questions
Are there any professional Combobox controls (dropdown list with autosuggestion) based on the jQuery library?
It should be able to handle large datasets and have some skinning options. A multi-column result list would be great too. I'm working with ASP.NET, but it's a not a problem if I had to write a wrapper for it.
I'm already using a third-party control, but I ran into some compatibilty issues between two vendor's controls. Well, I want to get rid of this kind of dependencies.
Source: (StackOverflow)
I've said it before and I'll say it again, the easiest examples for WPF are also the hardest to find on the web :)
I have a combo box that I need to display but it doesn't need to be databound or anything else, the content is static. How can I add a static list of items to my combo box using XAML?
Source: (StackOverflow)
I am a novice at JavaScript and jQuery. I want to show one combobox-A, which is an HTML <select>
with its selected id
and contents at the other place on onChange().
How can i pass the complete combobox with its select id
and how can I pass other parameters on fire of onChange event.
Source: (StackOverflow)
I want to connect a binding source to a list of class objects and then objects value to a combo box can anyone suggest how to do it
public class Country
{
public string Name { get; set; }
public IList<City> Cities { get; set; }
public Country()
{
Cities = new List<City>();
}
}
is my class and i want to bind its name field to a binding source which could be then associated with a combobox
Source: (StackOverflow)
In a WPF app, in MVP app, I have a combo box,for which I display the data fetched from Database. Before the items added to the Combo box, I want to display the default text such as
" -- Select Team --"
so that on pageload it displays and on selecting it the text should be cleared and the items should be displayed.
Selecting data from DB is happening. I need to display the default text until the user selects an item from combo box.
Please guide me
Source: (StackOverflow)
I have a combobox and I want to prevent the user from scrolling through the items with the mousewheel.
Is there an easy way to do that?
(C#, VS2008)
Source: (StackOverflow)
I want to have a "select-only" ComboBox
that provides a list of items for the user to select from. Typing should be disabled in the text portion of the ComboBox
control.
My initial Googling of this turned up an overly complex, misguided suggestion to capture the KeyPress
event.
Source: (StackOverflow)
Is there a CSS-only way to style a <select>
dropdown?
I need to style a <select>
form as much as humanly possible, without any JavaScript. What are the properties I can use to do so in CSS?
This code needs to be compatible with all major browsers:
- Internet Explorer 6,7 and 8
- Firefox
- Safari
I know I can make it with JavaScript: Example.
And I'm not talking about simple styling. I want to know, what the best we can do with CSS only.
I found similar questions on Stack Overflow.
And this one on Doctype.com.
Source: (StackOverflow)
I have a html form which has a select list box from which you can select multiple values because its multiple property is set to multiple. Consider form method is 'GET'. The html code for the form is as follows:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="get" action="display.php">
<table width="300" border="1">
<tr>
<td><label>Multiple Selection </label> </td>
<td><select name="select2" size="3" multiple="multiple" tabindex="1">
<option value="11">eleven</option>
<option value="12">twelve</option>
<option value="13">thirette</option>
<option value="14">fourteen</option>
<option value="15">fifteen</option>
<option value="16">sixteen</option>
<option value="17">seventeen</option>
<option value="18">eighteen</option>
<option value="19">nineteen</option>
<option value="20">twenty</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" tabindex="2" /></td>
</tr>
</table>
</form>
</body>
</html>
I want to display the selected values in select list box on display.php page. So how are the selected values accessed on display.php page using $_GET[] array.
Source: (StackOverflow)
In the post Enum ToString, a method is described to use the custom attribute DescriptionAttribute
like this:
Enum HowNice {
[Description("Really Nice")]
ReallyNice,
[Description("Kinda Nice")]
SortOfNice,
[Description("Not Nice At All")]
NotNice
}
And then, you call a function GetDescription
, using syntax like:
GetDescription<HowNice>(NotNice); // Returns "Not Nice At All"
But that doesn't really help me when I want to simply populate a ComboBox with the values of an enum, since I cannot force the ComboBox to call GetDescription
.
What I want has the following requirements:
- Reading
(HowNice)myComboBox.selectedItem
will return the selected value as the enum value.
- The user should see the user-friendly display strings, and not just the name of the enumeration values. So instead of seeing "
NotNice
", the user would see "Not Nice At All
".
- Hopefully, the solution will require minimal code changes to existing enumerations.
Obviously, I could implement a new class for each enum that I create, and override its ToString()
, but that's a lot of work for each enum, and I'd rather avoid that.
Any ideas?
Heck, I'll even throw in a hug as a bounty :-)
Source: (StackOverflow)
I have a ComboBox that doesn't seem to update the SelectedItem/SelectedValue.
The ComboBox ItemsSource is bound to a property on a ViewModel class that lists a bunch of RAS phonebook entries as a CollectionView, then I've bound (at separate times) both the SelectedItem or SelectedValue to another property of the ViewModel. I have added a MessageBox into the save command to debug the values set by the databinding, but the SelectedItem/SelectedValue binding is not being set.
The ViewModel class looks something like this:
public ConnectionViewModel
{
private readonly CollectionView _phonebookEntries;
private string _phonebookeEntry;
public CollectionView PhonebookEntries
{
get { return _phonebookEntries; }
}
public string PhonebookEntry
{
get { return _phonebookEntry; }
set
{
if (_phonebookEntry == value) return;
_phonebookEntry = value;
OnPropertyChanged("PhonebookEntry");
}
}
}
The _phonebookEntries collection is being initialised in the constructor from a business object. The ComboBox XAML looks something like this:
<ComboBox ItemsSource="{Binding Path=PhonebookEntries}"
DisplayMemberPath="Name"
SelectedValuePath="Name"
SelectedValue="{Binding Path=PhonebookEntry}" />
I am only interested in the actual string value displayed in the ComboBox, not any other properties of the object as this is the value I need to pass across to RAS when I want to make the VPN connection, hence DisplayMemberPath and SelectedValuePath are both the Name property of the ConnectionViewModel. The ComboBox is in a DataTemplate applied to an ItemsControl on a Window who's DataContext has been set to a ViewModel instance.
The ComboBox displays the list of items correctly, and I can select one in the UI with no problem. However when I display the message box from the command, the PhonebookEntry property still has the initial value in it, not the selected value from the ComboBox. Other TextBox instances are updating fine and displaying in the MessageBox.
What am I missing with databinding the ComboBox? I've done a lot of searching and can't seem to find anything that I'm doing wrong.
This is the behaviour I'm seeing, however it's not working for some reason in my particular context.
I have a MainWindowViewModel which has a CollectionView of ConnectionViewModels. In the MainWindowView.xaml file code-behind, I set the DataContext to the MainWindowViewModel. The MainWindowView.xaml has an ItemsControl bound to the collection of ConnectionViewModels. I have a DataTemplate that holds the ComboBox as well as some other TextBoxes. The TextBoxes are bound directly to properties of the ConnectionViewModel using Text="{Binding Path=ConnectionName}".
public class ConnectionViewModel : ViewModelBase
{
public string Name { get; set; }
public string Password { get; set; }
}
public class MainWindowViewModel : ViewModelBase
{
// List<ConnectionViewModel>...
public CollectionView Connections { get; set; }
}
The XAML code-behind:
public partial class Window1
{
public Window1()
{
InitializeComponent();
DataContext = new MainWindowViewModel();
}
}
Then XAML:
<DataTemplate x:Key="listTemplate">
<Grid>
<ComboBox ItemsSource="{Binding Path=PhonebookEntries}"
DisplayMemberPath="Name"
SelectedValuePath="Name"
SelectedValue="{Binding Path=PhonebookEntry}" />
<TextBox Text="{Binding Path=Password}" />
</Grid>
</DataTemplate>
<ItemsControl ItemsSource="{Binding Path=Connections}"
ItemTemplate="{StaticResource listTemplate}" />
The TextBoxes all bind correctly, and data moves between them and the ViewModel with no trouble. It's only the ComboBox that isn't working.
You are correct in your assumption regarding the PhonebookEntry class.
The assumption I am making is that the DataContext used by my DataTemplate is automatically set through the binding hierarchy, so that I don't have to explicitly set it for each item in the ItemsControl. That would seem a bit silly to me.
Here is a test implementation that demonstrates the problem, based on the example above.
XAML:
<Window x:Class="WpfApplication7.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="itemTemplate">
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=Name}" Width="50" />
<ComboBox ItemsSource="{Binding Path=PhonebookEntries}"
DisplayMemberPath="Name"
SelectedValuePath="Name"
SelectedValue="{Binding Path=PhonebookEntry}"
Width="200"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ItemsControl ItemsSource="{Binding Path=Connections}"
ItemTemplate="{StaticResource itemTemplate}" />
</Grid>
</Window>
The code-behind:
namespace WpfApplication7
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
DataContext = new MainWindowViewModel();
}
}
public class PhoneBookEntry
{
public string Name { get; set; }
public PhoneBookEntry(string name)
{
Name = name;
}
}
public class ConnectionViewModel : INotifyPropertyChanged
{
private string _name;
public ConnectionViewModel(string name)
{
_name = name;
IList<PhoneBookEntry> list = new List<PhoneBookEntry>
{
new PhoneBookEntry("test"),
new PhoneBookEntry("test2")
};
_phonebookEntries = new CollectionView(list);
}
private readonly CollectionView _phonebookEntries;
private string _phonebookEntry;
public CollectionView PhonebookEntries
{
get { return _phonebookEntries; }
}
public string PhonebookEntry
{
get { return _phonebookEntry; }
set
{
if (_phonebookEntry == value) return;
_phonebookEntry = value;
OnPropertyChanged("PhonebookEntry");
}
}
public string Name
{
get { return _name; }
set
{
if (_name == value) return;
_name = value;
OnPropertyChanged("Name");
}
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class MainWindowViewModel
{
private readonly CollectionView _connections;
public MainWindowViewModel()
{
IList<ConnectionViewModel> connections = new List<ConnectionViewModel>
{
new ConnectionViewModel("First"),
new ConnectionViewModel("Second"),
new ConnectionViewModel("Third")
};
_connections = new CollectionView(connections);
}
public CollectionView Connections
{
get { return _connections; }
}
}
}
If you run that example, you will get the behaviour I'm talking about. The TextBox updates its binding fine when you edit it, but the ComboBox does not. Very confusing seeing as really the only thing I've done is introduce a parent ViewModel.
I am currently labouring under the impression that an item bound to the child of a DataContext has that child as it's DataContext. I can't find any documentation that clears this up one way or the other.
I.e,
Window -> DataContext = MainWindowViewModel
..Items -> Bound to DataContext.PhonebookEntries
....Item -> DataContext = PhonebookEntry (implicitly associated)
I don't know if that explains my assumption any better?
To confirm my assumption, change the binding of the TextBox to be
<TextBox Text="{Binding Mode=OneWay}" Width="50" />
And this will show the TextBox binding root (which I'm comparing to the DataContext) is the ConnectionViewModel instance.
Source: (StackOverflow)
I have a requirement where I HAVE TO use bootstrap autocomplete dropdown, BUT user can have free form text in that dropdown if they wish. Before you think about TypeAhead, I could use Bootstrap TypeAhead textbox, but I need to have the dropdown becasue we want to give some default values as headstart options in case users dont know what to search for.
I am using this with MVC DropDownListFor as that creates a select control for us.
I found this article which does that for me.
https://github.com/danielfarrell/bootstrap-combobox/pull/20
All I had to do was take off the name from the select control and the control was letting me enter free form text. All good so far.
Now, I am using this in conjunction with Knockoutjs. I bind my options and selected value to the select control and then on row rendered of my template, I called (selector).combobox() which makes the select control a bootstrap comobobox and adds an input control and hides the select control in the scenes behind.
The problem now is when I try to get he values to post to server, since the value I put in input box is not a valid options from the options I gave to select control, it is always setting it to the first option by default. This is becasue, I set the binding of the selected value on select control and not on the input box which was created by bootstrap-combobox.js.
My question is how do I get the input box to data-bind to the same porperty as the the select control was bound to.
Any other options??
Let me know if you need more clarification or have questions.
Please suggest.
Thanks.
Source: (StackOverflow)
I know how to do it in code, but can this be done in XAML ?
Window1.xaml:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<ComboBox Name="ComboBox1" HorizontalAlignment="Left" VerticalAlignment="Top">
<ComboBoxItem>ComboBoxItem1</ComboBoxItem>
<ComboBoxItem>ComboBoxItem2</ComboBoxItem>
</ComboBox>
</Grid>
</Window>
Window1.xaml.cs:
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
double width = 0;
foreach (ComboBoxItem item in ComboBox1.Items)
{
item.Measure(new Size(
double.PositiveInfinity, double.PositiveInfinity));
if (item.DesiredSize.Width > width)
width = item.DesiredSize.Width;
}
ComboBox1.Measure(new Size(
double.PositiveInfinity, double.PositiveInfinity));
ComboBox1.Width = ComboBox1.DesiredSize.Width + width;
}
}
}
Source: (StackOverflow)
I'm using a modified version of the jQuery UI Autocomplete Combobox, as seen here:
http://jqueryui.com/demos/autocomplete/#combobox
For the sake of this question, let's say I have exactly that code ^^^
When opening the combobox, either by clicking the button or focusing on the comboboxs text input, there is a large delay before showing the list of items. This delay gets noticeably larger when the select list has more options.
This delay doesn't just occur the first time either, it happens every time.
As some of the select lists on this project are very large (hundreds and hundreds of items), the delay/browser freezing up is unacceptable.
Can anyone point me in the right direction to optimise this? Or even where the performance problem may be?
I believe the issue may be to do with the way the script shows the full list of items (does an autocomplete search for an empty string), is there another way to display all items? Perhaps I could build a one off case for displaying all items (as it is common to open the list before starting to type) that doesn't do all the regex matching?
Here is a jsfiddle to fiddle with:
http://jsfiddle.net/9TaMu/
Source: (StackOverflow)
I'm using .NET 2.0 and I'm trying to bind a combobox's Datasource to a sorted dictionary.
So the error I'm getting is "DataMember property 'Key' cannot be found on the Datasource".
SortedDictionary<string, int> userCache = UserCache.getSortedUserValueCache();
userListComboBox.DataSource = new BindingSource(userCache, "Key"); //This line is causing the error
userListComboBox.DisplayMember = "Key";
userListComboBox.ValueMember = "Value";
Source: (StackOverflow)