I've been pulling my hair out on this forever. I'm developing an application that has items with custom fields. Sometimes the user will choose an option from the custom field, sometimes they'll leave it blank. I'm trying to get a RadComboBox to display the selected item only if the item is not null. If the item is null, then the combobox should display nothing (or a notice it's blank).
What's happening is either the combobox does not keep in sync, or it defaults to the first item in the collection. I need it to be in sync, but not default to the first item in the list if the property is null. For example simplified view of my ViewModel:
Class CustomField: Id as Integer, Description as String
ViewModel:
Public Property Selection as CustomField
Public Options as ObservableCollection(Of CustomField)
WPF:
<telerik:RadComboBox x:Name="rcbDropDown"
ItemsSource="{Binding Path=Options}"
SelectedValuePath="Id"
DisplayMemberPath="Choice"
SelectedItem="{Binding Path=Selection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ClearSelectionButtonContent="Clear"
ClearSelectionButtonVisibility="Visible"
IsEditable="False"
IsReadOnly="{Binding Path=IsReadOnly}"
EmptyText="Not Set"
UpdateSelectionOnLostFocus="True"
/>
I've tried multiple combinations of SelectedItem Mode=TwoWay, OneWayToSource and IsSyncronizedWithCurrentItem=True/False/NULL
I either end up with them syncing and the combo box defaulting to the first item on the list automatically, and pushing that into the viewmodel when the record is viewed, or not syncing. I can't get it to only show the selected item when it's not null. Any help would be appreciated!
I have a quite strange behavior for ComboBox
When I set IsReadOnly to true the ReadOnlyBorderBrush of the theme is apllied but ReadOnlyBackBrush is not, also it is not really read only value can still be changed by the user. To avoid this I have set IsReadOnly to true and IsEnabled to false in that case neither Border nor BackBrush is applied.
What am I missing here?
Here is a example 1st Combox has IsReadOnly="True" IsEnabled="False", 2nd Combox only IsReadOnly="True" and at the bottom a TextBox with only IsReadOnly="True" as reference.
I've been working with the Telerik WPF controls for the last couple of months and appreciating them.
<rant>
However, I have a major gripe as well: most of the examples are FAR too complex. Here's a perfect example. I'm trying to get a ComboBox to work with a GridView. There is an example that does pretty much exactly what I want at https://github.com/telerik/xaml-sdk/tree/master/ComboBox/DropDownWithHeaders. However,
There is also an example of this at https://www.telerik.com/forums/radcombobox-with-radgridview, but it suffers from the same problems.
This kind of thing seriously makes me ponder going back to our old controls provider.
</rant>
Now, can someone please provide me with a simple example of a ComboBox that uses a GridView for the drop-down?
Of course perhaps I'm using the wrong control. Maybe I should be using the MultiColumnComboBox, but the end results shown in the examples make it look nothing like a traditional ComboBox. (Again, that may be owing to a lack of a good, simple example.)
Help?
We were using a standard Window object as the parent for our MainWindow. All was good. Then we wanted to do theming...couldn't do it easily, we found we needed to change to telerik:RadWindow. That's when everything went.....bad. No more window icons, no more task bar icon, no more showing up in taskbar. We've been able to figure out msot things and add more code to "fix" what we thought should be part of the default behaviour.
Then this morning my boss uses the mouse to try to change a value in a RadComboBox.....nope. Huh? I must have done something wrong? I don't think so. The change is in git and linked to the exact date we changed from Window to RadWindow..
How are you supposed to get mouse selections to work with a RadComboBox contained in a RadWindow?
Hi,
I would like to have the DataFormComboBoxField behave the same way as the Edit mode: Editable, Read-Only and Auto Complete ad in your demo application. But when I set it to readonly it is disabled.
My code:
e.DataField = new DataFormComboBoxField()
{
ItemsSource = _componentsDS.ComponentKeyWords,
SelectedValuePath = "KeyWordId",
DisplayMemberPath = "Abbreviation",
DataMemberBinding = new Binding("KeywordId") { Mode = BindingMode.TwoWay },
IsComboboxEditable = true,
IsReadOnly = true,
Label = "Keyword"
};
The example in your application:
Kind regards,
Johan
i have a combo box that i need when i select one of it's items, it will open a new sub combo box to choose a sub item
is it feasible?
FrameworkElement focusedElement = Keyboard.FocusedElement as FrameworkElement; if (focusedElement != null) { string focusedControlName = focusedElement.Name; if (focusedControlName == "txtPolicyNumber") { iefInsuranceThirdPartyVM.CanAutoDrop = true; txtPolicyNumber.Focus(); // WTF is making it focus on the combobox } }
We have a issue with WPF RadComboBox to disable the auto selection of first item while databinding.
I have large set of data (say 10000 items) in the application cache.
<telerik:RadComboBox
x:Name="itemBox"
HorizontalAlignment="Stretch"
telerik:TextSearch.TextPath="Name"
CanAutocompleteSelectItems="False"
DisplayMemberPath="Name"
EmptyText="Select item"
IsEditable="True"
IsFilteringEnabled="True"
IsReadOnly="False"
IsTextSearchEnabled="True"
ItemsSource="{Binding ItemCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
OpenDropDownOnFocus="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextSearchMode="Contains">
<telerik:EventBinding
Command="{Binding BeginSearchCommand}"
EventName="KeyUp"
PassEventArgsToCommand="True" />
</telerik:RadComboBox>
We have the RadCombobox with Filter enabled.
BeginSearchCommand relay command method has implementation of filtering the cached ItemCollection and setting the value.
this.ItemCollection = new QueryableCollectionView(new ObservableCollection<ItemModel>(filtereditems));
I first load 50 items in RadCombobox and the user will try to search the items from SearchText . Then the items in the cache is filtered with searchtext and the result is assigned with the datasource property.
The couple of action above continues. Please help us disable autoselect while databinding.
Hi,
I have a problem, that I cannot solve. I have a Grid View (see attachment) based on a SQL Table. Now have replaced some colums with a comboBox.
The comboBoxes receive the data from the following table.
| ID | Country | Plant | Area | Machine |
------------------------------------------------
| 1 | DE | MUC | BA | A |
| 2 | DE | MUC | BA | A |
| 3 | AT | VIE | BE | 1 |
| 4 | AT | VIE | BE | 2 |
F.e. The column "Country" in my GridView has as ItemSource a grouping of the column Country. Now I want to update the comboBox "Plant" depending on the value of the ComboBox "Country" meaning that when "DE" is chosen, it should only show "MUC" as a possible entry. How can I do that? Here is my code.
Thanks.
public partial class MainWindow : Window
{
private SqlConnection connection;
private string dbName = string.Empty;
public MainWindow()
{
InitializeComponent();
LoadData();
}
private void LoadData()
{
try
{
string connectionString = "Data Source=localhost;Initial Catalog=Test_DB;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string query = "SELECT * FROM dbo.MachineAreas";
SqlDataAdapter adapter = new SqlDataAdapter(query, connection);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
gridMachineAreas.ItemsSource = dataTable.DefaultView;
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void GridMachineAreas_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
switch ((e.Column as GridViewDataColumn).DataMemberBinding.Path.Path)
{
case "ID":
var newColumn1 = new GridViewDataColumn();
newColumn1.CopyPropertiesFrom(e.Column);
newColumn1.Header = "ID";
newColumn1.Width = 60;
e.Column = newColumn1;
break;
case "Country":
var newColumn2 = new GridViewComboBoxColumn();
newColumn2.CopyPropertiesFrom(e.Column);
newColumn2.Header = "Country";
newColumn2.Width = 60;
newColumn2.UniqueName = "Country";
newColumn2.IsComboBoxEditable = false;
newColumn2.ItemsSource = MakeCountryCollection();
e.Column = newColumn2;
break;
case "Plant":
var newColumn3 = new GridViewComboBoxColumn();
newColumn3.CopyPropertiesFrom(e.Column);
newColumn3.Header = "Plant";
newColumn3.Width = 60;
e.Column = newColumn3;
break;
case "Area":
var newColumn4 = new GridViewComboBoxColumn();
newColumn4.CopyPropertiesFrom(e.Column);
newColumn4.Header = "Area";
newColumn4.Width = 60;
e.Column = newColumn4;
break;
case "Machine":
var newColumn5 = new GridViewComboBoxColumn();
newColumn5.CopyPropertiesFrom(e.Column);
newColumn5.Header = "Machine";
newColumn5.Width = 60;
e.Column = newColumn5;
break;
}
}
private List<string> MakeCountryCollection()
{
List<string> countryCollection = new List<string>();
string query = "SELECT Country FROM dbo.MachineAreas Group By Country";
try
{
string connectionString = "Data Source=localhost;Initial Catalog=Test_DB;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(query, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string value = reader.GetString(0);
countryCollection.Add(value);
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
return countryCollection;
}
}
Hello, Telerik
I want to create a feature with the following characteristics:
1. Use of the MVVM pattern.
2. The number of columns in the DataGridView is not fixed but dynamic. (Users can specify the number of columns as an option, allowing for dynamic changes.)
3. Only the first column's text is fixed, while the 2nd to nth columns are ComboBoxes, allowing users to select which columns they want to view.
For example, if a class has (name, age, gender, department, major, student number, average grade, highest grade, lowest grade) as fields,
'Name' is always shown in the first column as fixed data.
'Age' to 'Lowest Grade' are available as ComboBox options for users to select and view as they wish.
If n = 5, it could be displayed as follows:
1st | 2nd | 3rd | 4th | 5th
Name (Fixed) | Age | Gender | Major | Avg Score
or
1st | 2nd | 3rd | 4th | 5th
Name (Fixed) | Major | Avg Score | Max Score | Min Score
In this way, users can view data in the columns of their choice.
As mentioned, since the number of columns is dynamic, I don't want to write the column code as below.
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="column 1" DataMemberBinding="{Binding data_1}"/>
<telerik:GridViewDataColumn Header="column 2" DataMemberBinding="{Binding data_2}"/>
<telerik:GridViewDataColumn Header="column .." DataMemberBinding="{Binding data_1}"/>
<telerik:GridViewDataColumn Header="column n" DataMemberBinding="{Binding data_n}"/>
</telerik:RadGridView.Columns>
I searched all the SDK examples and forums, but I don't know how to write it.
Thank you in advance.