Change Telerik GricViewComboBox Append List Font - c#

i have a Telerik GridView with a ComboBox Column, while filtering in this Combobox an appending list dropped down.
Same as the image below...
So i want to make the font of the Append list larger.
How to do it?

RadDropDownList uses different popups for its default items representation and for its auto complete suggest items. Here is an example demonstrating how to change the font of both:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
if (editor != null)
{
editor.DropDownStyle = RadDropDownStyle.DropDown;
RadDropDownListEditorElement element = (RadDropDownListEditorElement)editor.EditorElement;
element.VisualItemFormatting -= element_VisualItemFormatting;
element.AutoCompleteSuggest.DropDownList.VisualItemFormatting -= element_VisualItemFormatting;
//this handles the default drop down formatting - when you press the arrow key to open the drop down
element.VisualItemFormatting += element_VisualItemFormatting;
//this handles the suggest popup formatting
element.AutoCompleteSuggest.DropDownList.VisualItemFormatting += element_VisualItemFormatting;
}
}
void element_VisualItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
args.VisualItem.Font = new Font("Arial", 16);
}

You could either make a CellTemplate with your font, or you could handle the CellFormating event and do something like this:
void radGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
// For all cells under the Account Name column
if(e.CellElement.ColumnInfo.Name == "Account Name")
{
if(e.CellElement.Value != null)
{
System.Drawing.Font newfontsize = new System.Drawing.Font(e.CellElement.Font.FontFamily.Name,20);
for each(GridViewCellInfo cell in e.Row.Cells)
{
e.CellElement.Font = newfontsize;
}
}
}
// For all other cells under other columns
else
{
e.CellElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.Font, Telerik.WinControls.ValueResetFlags.Local);
}
}
Plug in whatever size font you want for the "newfontsize" variable. Also note that, the else statement may not be necessary in your case, but you can reset the font to default using the ResetValue property.

Related

Increase font size of ListItem in Combo box that comes as suggested in dropdown

I am using Combo box while creating Desktop Application using C# in Visual Studio, I increased the font size to "20" now when I run the application and click the dropdown button list elements font-size also increased.
That's fine. But, when I write something in the combo box it gives suggestions as shown in the picture below.
I, also want to increase the font size of this suggestion list, I have set "AutoCompleteMode" property set to "suggest". Is anybody can help me with this?
The font of the auto-complete text presented is fixed. There is no corresponding properties to set it.
A workaround is that you can create a custom control and replace the suggest-drop-down with custom listbox.
public Form1()
{
InitializeComponent();
comboBox1.Size = new Size(120, 30);
listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
}
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Text = listBox.Text;
listBox.Visible = false;
}
ListBox listBox = new ListBox();
// event triggered when the user enters text
private void comboBox1_TextUpdate(object sender, EventArgs e)
{
// set the font of listbox to be consistent with combobox
listBox.Font = comboBox1.Font;
// add listbox below combobox
listBox.Location = new Point(comboBox1.Location.X, comboBox1.Location.Y + comboBox1.Height);
// filter suggest items
listBox.Items.Clear();
foreach (string item in comboBox1.Items)
{
if (item.StartsWith(comboBox1.Text) && comboBox1.Text != string.Empty)
{
listBox.Items.Add(item);
}
}
listBox.Visible = listBox.Items.Count > 0;
this.Controls.Add(listBox);
}
Test result:
Those are actually two areas which you can configure independently. According to this MSDN article,
To change settings:
Go to Tools – Options – Environment - Fonts and Colors
Under Show settings for: select either Statement Completion or Editor Tooltips (for Parameter Info and Quick Tips)
Change either the font or font size

Selecting an item in a combo cause a cyclic call

I am writing a winform application.
On the form I have a Label and a combobox.
The combobox is populated with fonts names. When selecting a font from it, the label's font text is changing accordingly. When clicking on the label, the combobox's selecteditem is set accordingly.
The problem is when I am selecting the label, I get a cyclic call: I am setting the combobox item according to the font of the label, then the SelectedIndexChanged is fired which is in charge to set the font name of the label (ChangeLabelFont).
So the label font is again updated while it is the trigger of all those calls.
private void FontToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (_selectedLabel == null)
{
return;
}
ChangeLabelFont(FontNameToolStripComboBox.SelectedItem.ToString(), FontSizeToolStripComboBox.SelectedItem.ToString());
}
private void SelectLabel(Point location)
{
SetComboBoxesFont(_selectedLabel.Font.Name, _selectedLabel.Font.Size);
}
private void SetComboBoxesFont(string name, float size)
{
FontNameToolStripComboBox.SelectedItem = name;
FontSizeToolStripComboBox.SelectedItem = size;
}
private void ChangeLabelFont(string name, string size)
{
if (_selectedLabel == null)
{
return;
}
FontFamily fontFamily = new FontFamily(name);
float fontSize = float.Parse(size);
_selectedLabel.Font = new Font(fontFamily, fontSize);
}
Is there a way to prevent this cyclic call? Maybe I am doing something wrong?
There is something missing in the code you're showing. I'd like to see the ChangeLabelFont method as well as the handler for the "select label" event. But I suppose it's the SelectLabel method in the end. So how about using a member flag:
private bool m_bInhibitCycle = false;
private void SelectLabel(Point location)
{
if (m_bInhibitCycle) return;
m_bInhibitCycle = true;
SetComboBoxesFont(_selectedLabel.Font.Name, _selectedLabel.Font.Size);
m_bInhibitCycle = false;
}

How do i change my devexpress code to work for only the cell I hover over in tooltip event

The tooltip is working now when hovering over the row of the grid. I need to change it to only do the tooltip when hovering over the 2nd column of the grid. If I am on the column then I need the value in the cell that I just hovered over. Can't seem to get to work. If I use: hitInfo.Column.FieldName that will only work if I don't use the row info. What do I need to add here?
private void StrGridToolTipController_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{
GridHitInfo hitInfo = gridViewST.CalcHitInfo(e.ControlMousePosition);
if (hitInfo.HitTest == GridHitTest.RowIndicator)
{
Something lc = gridViewST.GetRow(hitInfo.RowHandle) as Something;
//get the cell value to use in rest of the code
//do the tooltip string of data - that is working
This is the VB code we use to when providing tooltips for a specific column....
Dim info As Views.Grid.ViewInfo.GridHitInfo = _gv.CalcHitInfo(e.ControlMousePosition)
If info.InRowCell Then
If info.Column.FieldName = "KPIStatus" Then
...
You need to check the value of GridHitInfo.InRowCell property and compare the value of GridHitInfo.Column property to second value in ColumnView.VisibleColumns collection. To get the value of cell you can use GridView.GetRowCellValue method with GridHitInfo.RowHandle property.
Here is example:
private void StrGridToolTipController_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{
if (e.SelectedControl == gridViewST.GridControl)
{
var info = gridViewST.CalcHitInfo(e.ControlMousePosition);
if (info.InRowCell && info.Column == gridViewST.VisibleColumns[1])
{
object value = gridViewST.GetRowCellValue(info.RowHandle, info.Column);
//do the tooltip string of data
}
}
}

Add dropdown for a specific cell in a datagridview

I am trying to add different controls to cells in the same column. The drop down does not show and there is no visible setter:
private void AddBooleanDropDown(DataGridView grid, int row, KeyValuePair<string, string> kvp)
{
DataGridViewComboBoxCell dropDownCell = new DataGridViewComboBoxCell();
dropDownCell.DataSource = new string[] { "True", "False" };
grid.Rows[row].Cells["Value"] = dropDownCell;
}
Not sure if this will be helpful to you, but maybe an alternative method?
I wanted to be able to update an excel spreadsheet that I read into a DataGridView and give the user a few options. I used a ContextMenuStrip that would display on a MouseClick event.
It displays a small menu when you right click on a cell:
If it's not what you're looking for at all, sorry; just perhaps an alternate solution:
////////////////////////////////////////////////////////////////////////
//Change Priority Strip
////////////////////////////////////////////////////////////////////////
ContextMenuStrip changePriority = new ContextMenuStrip();
ToolStripMenuItem highPriority = new ToolStripMenuItem("High Priority");
changePriority.Items.Add(highPriority);
highPriority.Click += new EventHandler(changePriorityHighEvent);
ToolStripMenuItem normalPriority = new ToolStripMenuItem("Normal Priority");
changePriority.Items.Add(normalPriority);
normalPriority.Click += new EventHandler(changePriorityNormalEvent);
ToolStripMenuItem lowPriority = new ToolStripMenuItem("Low Priority");
changePriority.Items.Add(lowPriority);
lowPriority.Click += new EventHandler(changePriorityLowEvent);
////////////////////////////////////////////////////////////////////////
private void gridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right) //On Right Click
{
DataGridView.HitTestInfo hit = gridView.HitTest(e.X, e.Y); //Get the clicked cell
if (e.RowIndex < 0) //If it's a header, ignore
return;
gridView.CurrentCell = gridView[e.ColumnIndex, e.RowIndex]; //Select the cell for future info
if (gridView.CurrentCell.ColumnIndex == 6) //If this is the priority column
{
changePriority.Show(Cursor.Position.X, Cursor.Position.Y); //Show the strip
}
}
}
private void changePriorityHighEvent(Object sender, EventArgs e) {
//make changes
}
private void changePriorityNormalEvent(Object sender, EventArgs e) {
//make changes
}
private void changePriorityLowEvent(Object sender, EventArgs e) {
//make changes
}
Here is very good MSDN Example.
The DataGridView control provides several column types, enabling your users to enter and edit values in a variety of ways. If these column types do not meet your data-entry needs, however, you can create your own column types with cells that host controls of your choosing. To do this, you must define classes that derive from DataGridViewColumn and DataGridViewCell. You must also define a class that derives from Control and implements the IDataGridViewEditingControl interface.
Not sure if you can change a specific cell in a grid unless it's the same type.
You could try adding a new column of combo boxes all with that data source
var newCol = new DataGridViewComboBoxColumn()
{
DataSource = new string[] { "True", "False" }
};
grid.Columns.Add(newCol);
also you might want to check that the int your passing in isn't greater than the number of rows.

How to extract font size of content

I've been working on making my own little text editor using a RichTextBox(MyRTB). I've made a Combobox to change the font of the selected text within the RichTextBox when the value changes using this code block:
private void CmbFont_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MyRTB != null)
{
string fontsize = (((ComboBoxItem)CmbFont.SelectedItem).Content).ToString();
MyRTB.Selection.ApplyPropertyValue(Run.FontSizeProperty, fontsize);
}
}
Now I'd like my Combobox value to change every time I select a string of text within the RichTextBox that has a different font size. Is this possible?
Thanks
Add an event handler to the selection changed event. In that event handler get the TextElement.FontSizeProperty from the RichTextBox selection
...
MyRTB.SelectionChanged += OnSelectionChanged;
...
void OnSelectionChanged()
{
var fontSize = MyRTB.Selection.GetPropertyValue(TextElement.FontSizeProperty);
if (fontSize == DependencyProperty.UnsetValue)
{
// Selection has text with different font sizes.
}
else {
// (double)fontSize is the current font size. Update Cmb_Font..
}
}
Make sure you don't call OnSelectionChanged & CmbFont_SelectionChanged recursively.

Categories