combobox disable edit and enable default selection c++ builder - combobox

I'm using combobox and I would like to disable user from edit,thus, I set ComboBox's Style property to csDropDownList and also I would like to set text field in order to enable default selection.
How can I do it?
(used in borland c++ builder bcb6)
Thanks!

You need to set the ItemIndex property, where
-1 means no item is selected
0, 1, 2, 3, etc will select an item at that index.
If, for some reason, you need to also restore text (sometimes different BCB versions behave differently) then you need to also set the Text property to one from the TStrings Items ... (indexed by ItemIndex).

Related

SelectedCells in DataGrid Returning Null

I am trying to record the selected cells that a user selects in a WPF Datagrid. Using Powershell to do this, I am using the .SelectedCells property of the DataGrid object. When I use this against the DataGrid object, I write the results to host. Although I select cells in the GUI, nothing returns to the console. It does however, create blank spaces where values should go; thus, I know the event handler is working. I can successfully return a single value that is selected - more specifically, the current one - if I use the .CurrentCell property of the DataGrid Object (Go Figure). I have been looking for solutions on Google. Found plenty for C# and DataGridView. This is not a DataGridView, but a DataGrid from WPF.
Code:
$UI.DataGrid.Add_SelectedCellsChanged({
# Returns nothing
Write-Host $UI.DataGrid.SelectedCells
# Returns current selected cell (which it should)
Write-Host $UI.DataGrid.CurrentCell.'Column 1'
})
Note: I cannot use the 'Column 1' property with the SelectedItems property. I'm not entirely sure why, but I have reason to believe that is hindering me from returning results.
Update:
Problem lies within the selection mode in the XAML code. Once it is on "Cells", it doesn't allow me to select the column property. Once I changed the selection mode to "Row", I can easily select the column property. Investigating this now.

autocompletemode equivalent in system.windows.controls.combobox

I have an editable combo-box where the user could select (or type) one of the values from the drop-down, or a different value altogether.
I need the autocomplete functionality, which is essentially showing a subset of values in the drop-down when one or more characters are entered.
I see there is an autocompletemode property in system.windows.forms.combobox, which would have probably served my purpose but, is there an equivalent in WPF system.windows.controls.combobox?
The WPF Toolkit Autocomplete Box is what you need. This tutorial should get you started.

Combox with fill-in option

I want to add to WPF Form a ComboBox which is bound to a datasource (in my viewmodel). But besides from the choices in my viewmodel I would also like to add the option of allowing a fill-in value.
How could I achieve something like that in XAML?
The first thing you need to do is turn on isEditable. I'm assuming that you also want to have the new value added to your datasource. If that is true then you will have to do some code since this is not possible with pure xaml. Here is an example of how to do this.

Background color of rows in WPF datagrid

I've got a WPF datagrid bound to a list of parts and I need alternating row colors. The parts can also be part of a group, in which case the entire group needs to be the same color. Kind of like:
Part 1, group 1 - White background
Part 2, group 2 - Blue background
Part 3, group 3 - White background
Part 4, group 3 - White background
Part 5, group 4 - Blue background
Part 6, group 4 - Blue background
Part 7, group 5 - White background
The alternation of color must be based on groups, not simply by every other row. I have tried using grid.ItemContainerGenerator in the codebehind when the source collection is updated, but this does not work. ItemContainerGenerator.ContainerFromIndex() always returns null at this time, I suppose because the grid is still updating, I don't know. How can I do this?
In complex scenarios (like color denoting status, for example), I create a property on the viewmodel that returns a Color for the BackgroundBrush based on whatever rules you want. I typically create a static instance that I return repeatedly for each group, and freeze it, to conserve resources.
HTH...
I have used RowLoaded/RowUnloaded in the past, and using a behavior told the row what property of the rows datacontext contains the background. The problem that I have found is that binding a rows Background for some reason climbs up to the Grid's DataContext, instead of using the rows. If you are interested in this approach I can paste the code I have use. It does require that the ViewModel or ListViewModel be aware enough to set the correct colors for the rows. I have been often on the fence about colors in ViewModel, but color has become a business need and not just an ascetic effort.
What I did was overriding the following event of the DataGrid class
protected override void PrepareContainerForItemOverride(System.Windows.DependencyObject element, object item)
After calling the base method, you can set background color of the row based on the value of the item variable, which you can convert to group class and access properties such as group name for example.

Multiple choice on WinForms

What's the best way of implementing a multiple choice option in Windows Forms? I want to enforce a single selection from a list, starting with a default value.
It seems like a ComboBox would be a good choice, but is there a way to specify a non-blank default value?
I could just set it in the code at some appropriate initialisation point, but I feel like I'm missing something.
If you only want one answer from the group, then a RadioButton control would be your best fit or you could use the ComboBox if you will have a lot of options. To set a default value, just add the item to the ComboBox's collection and set the SelectedIndex or SelectedItem to that item.
Depending on how many options you are looking at, you can use a ListBox with the SelectionMode property set to MultiSimple, if it will be multiple choice or you could use the CheckBox control.
You should be able to just set the ComboBox.SelectedIndex property with what you want the default value to be.
http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindex.aspx
Use the ComboBox.SelectedItem or SelectedIndex property after the items have been inserted to select the default item.
You could also consider using RadioButton control to enforce selection of a single option.
You can use a ComboBox with the DropDownStyle property set to DropDownList and SelectedIndex to 0 (or whatever the default item is). This will force always having an item from the list selected. If you forget to do that, the user could just type something else into the edit box part - which would be bad :)
If you are giving the user a small list of choices then stick with the radio buttons. However, if you will want want to use the combo box for dynamic or long lists. Set the style to DropDownList.
private sub populateList( items as List(of UserChoices))
dim choices as UserChoices
dim defaultChoice as UserChoices
for each choice in items
cboList.items.add(choice)
'-- you could do user specific check or base it on some other
'---- setting to find the default choice here
if choice.state = _user.State or choice.state = _settings.defaultState then
defaultChoice = choice
end if
next
'-- you chould select the first one
if cboList.items.count > 0 then
cboList.SelectedItem = cboList.item(0)
end if
'-- continuation of hte default choice
cboList.SelectedItem = defaultChoice
end sub

Resources