I am using silverlight and my combobox is like this:
ComboBox cb = new ComboBox();
Suppose it already contains Items which are visible only on clicking the combobox.
I want add a vertical scrollbar(or slider) programatically when it shows its items. Is there any inbuilt property for this in silverlight or do I need to use scrollbar or slider for it?
There is an inbuilt property of ScrollViewer.VerticalScrollbarVisibility. Set its value to Visible.
For more read this
You can try changing the dropdownheight property.
cb.DropDownHeight = cb.ItemHeight * 5;
This is to view only 5 items at a time
You can go to Properties:
And set your specified height here.
Related
I have a datagrid, which is populated programatically by data retrieved from a webservice. The last column of the datagrid contains checkboxes, which allow to show each rows value on a map. The column is created with a template column like this:
DataGridTemplateColumn column = new DataGridTemplateColumn();
column.Header = "Show on map";
DataTemplate dt = new DataTemplate();
FrameworkElementFactory checkBoxFactory = new FrameworkElementFactory(typeof(CheckBox));
checkBoxFactory.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(CheckBoxClicked), true);
dt.VisualTree = checkBoxFactory;
column.CellTemplate = dt;
DataGrid.Columns.Add(column);
If the users clicks on one of the checkboxes, the CheckBoxClicked method is invoked and displays the corresponding row values as an icon on the map (as already mentioned). This works very well. However, the user may close the window containing the datagrid, whereas the map stays on the screen, together with the displayed icons.
Now, when the user reopens the window with the datagrid, I'd like to preselect the checkbox, according to the already showing icons. Since the checkboxes do not have a binding, I'm unable to match the icons to them.
How can this be done? Is there a way to programatically preselect them? Or is there still a way to create a binding?
Finally, I've found the solution. Hosch250s comment lead me on the right track (how can I upvote the comment?). The answer can be found here: binding in code.
The easiest way set the checkbox state programmatically is to create this binding:
Binding binding = new Binding("IsChecked");
binding.Mode = BindingMode.OneWay;
binding.Source = this;
checkBoxFactory.SetBinding(CheckBox.IsCheckedProperty, binding);
And implement the property in the current context:
public bool IsChecked {
get {
return doWhateverToFindOutIfChecked();
}
}
The first approach (see my answer with method binding) was simple and strait forward. However, one can not really determine, for which row the binding is called. I've changed the soluntion as followed:
Instead of a DataGridTemplateColumn I'm using a DataGridCheckBoxColumn, now. My data is dynamically stored in rows and bound to the ItemsSource property, using a ListCollectionView. The boolean values, required for the checkbox columns are dynamically inserted into the row values. My datagrid is read only and the selection unit is cell. Settings these properties, I can us the MouseUp event to detect a mouse click on a cell. Inside the handler method, I'll check if the click belonged to a checkbox cell. If so, I change the corresponding boolean value in the row values and call Items.refresh().
I have a DocumentContent (AvalonDock) which contains a textEditor. I want to add a toolbar to it at runtime. To do this I need to add a GridDefinition so that the first row has a fixed height (for the toolbar) and the rest of the document content should be filled by the texteditor.
I created a new Grid and added a row definition to it and added the child to it but I don't know how to attach this to the DocumentContent. I am not even sure if it is the right way to add the toolbar. Any suggestions ?
Grid grid = new Grid();
RowDefinition rowDefinition1 = new RowDefinition();
rowDefinition1.Height = new GridLength(32);
grid.RowDefinitions.Insert(0, rowDefinition1);
grid.Children.Insert(0, new IsaDocToolbar());
PS: I forgot to mention that I use AvalonDock 1.3
Why are you doing this in code and not using XAML?
Here is the basic idea/concept using MVVM in XAML
Document content should be a grid with 2 rows
1st row for toolbar
2nd row for text editor
Visibility of the first row can be controlled using binding to a Boolean property and by using BoolToVisibilityConverter.
Hope this helps. I have been doing something similar (not on the document content) for the application. You can checkout my Wide project for a similar concept for toolbars for the window.
How can I set a dropdownlist control's height in C#?
I tried this, but it doesn't work:
cbo.Attributes.Add("style", "height: 50%");
And, how can I make sure a dropdownlist's list is always dropped down rather than up?
At last I got it..
cbo.Height = new Unit("250px");
I can set dropdownlist height with above code.
Temporarily you can increase the font size of the items in the dropdown control, this will set height. Will try to find a better solution.
The answer to "How to set height" is:
cbo.Height = new Unit("250px");
You can set the height of a dropdownlist as follows:
combobox1.DropDownHeight = 106;
Make sure that the DrawMode attribute of the combobox is set to Normal. This way it's items can be populated without much difficulty.
Hi I want to adjust the row height of datagrid programatically at runtime,
I am using the below code :
dgRates.DataSource = dsRates.Tables[0];
foreach (DataGridColumnStyle vColumnStyle in dgRates.TableStyles[0].GridColumnStyles)
{
vColumnStyle.Width = 60;
}
But I am getting the
"ArgumentOutOfRangeException Parameter
name: index".
Please tell me how to resolve this
Thanks in advance
You're adjusting the width of the columns, not the height of the rows (or at least, trying to). Rows in a data grid are set globally, using dg.RowHeight, or you can set the Height property on the DataGridViewRows individually.
How can I make a listbox dropdown like a combobox?
Or is it possible to configure a combobox so that the user can't add values but rather only select from the available list of values?
This is for a desktop application.
The ComboBox control has a DropDownStyle property used to set this. Set it to DropDownList.
Set the DropDownStyle to DropDownList:
Specifies that the list is displayed by clicking the down arrow and that the text portion is not editable. This means that the user cannot enter a new value. Only values already in the list can be selected. The list displays only if AutoCompleteMode is Suggest or SuggestAppend.
like:
DropDownStyle = DropDownList;
Set the ComboBox.DropDownStyle property to DropDownList - that should give you the behaviour you need