Disable right-click menu in ComboBox in c# [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
My ultimate goal is to make Combobox un-editable. Currently when user makes any selection then ComboBox shows selection and highlights it, therefore user can right-click and cut and delete the text that appears. I have added keyDown method, which prevents user from command such as ctrl + c, ctrl + v and delete. But User can still modify highlighted Text using right-click 'cut', 'copy' and 'paste'. How can i prevent user from modifying the current selection?

Ultimate goal is to make Combobox un-editable.
You could subscribe to KeyDown event and set SuppressKeyPress to true for all other actions other than Ctrl+c and create new ContextMenu to disable all default behavior.
comboBox2.KeyDown += comboBox2_KeyDown;
comboBox2.ContextMenu = new ContextMenu(); //disable right click
void comboBox2_KeyDown(object sender, KeyEventArgs e)
{
if (!(e.Control && e.KeyCode == Keys.C))
{
e.SuppressKeyPress = true;
}
}

Related

How do I control which element is "selected" by default when the WPF application starts - i.e., where the keyboard cursor is by default on startup? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Specifically, I want to be able to launch my WPF (C#) application and then immediately be able to switch between two radio buttons using the arrow keys.
As it is, I need to use the Tab key or the mouse to "select" one of the radio buttons, and then I can start hopping between them using arrow keys.
Important note: I am not asking how to control which radio button is checked by default. I'm asking how to how to optimize keyboard user-friendliness of my WPF controls.
You can use the Focus () function to choose the item selected when the window opens.
public MainPage()
{
InitializeComponent();
Button1.Focus();
}
And you can define TabIndex orders to optimize the user experience.
In Xaml :
<Button x:Name="Button1" TabIndex="0"/>
<Button x:Name="Button2" TabIndex="1"/>
<Button x:Name="Button3" TabIndex="2"/>
Or in C# :
Button1.TabIndex = 0;
Button2.TabIndex = 1;
Button3.TabIndex = 2;

Detect when none of app windows is active/focused [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How detect when user changes focus from multi-window application (alt+tab e.g.).
I want to detect when none of the app windows is active/focused.
First window is always shown but user can work with up to four windows(none of these is shown as dialog).
Form has a ContainsFocus property that indicates whether the form, or one of its child controls has the input focus. You can check this property for all open forms to detect if the application contains focus or not:
var isActive = Application.OpenForms.Cast<Form>().Any(x=>x.ContainsFocus);
Also as another option:
var isActive = (Form.ActiveForm != null)
If you want to be notified of the state of the application you can handle Activate and Deactivate event of your forms for all forms.
private void f_Deactivate(object sender, EventArgs e)
{
BeginInvoke(new Action(() =>
{
if (Form.ActiveForm == null)
Text = "App Deactivated.";
else
Text = "Still Active";
}));
}

how to add Buttons in datagrid view using C# .net [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How to add buttons in DataGridView using WinForms application in c# .NET?
In this picture, you can see that buttons are add in rows for delete, edit and active columns names. Like that way, I want to add buttons in DataGrid view in WinForms.
Right click in your datagridview.
In pop-up select Add Column.
In add column pop-up you can choose DataGridViewButtonColumn.
Just make a function which and call it on form load function
Public void AddButton()
{
//Add button
DataGridViewButtonColumn EditButton = new DataGridViewButtonColumn();
EditButton.UseColumnTextForButtonValue = true;
EditButton.DataPropertyName = "btnColumn";
EditButton.Text = "Button Text";
DataGridView_name.Columns.Add(EditButton);
}
If you want to add it manually from code

Visual studio - toggle switch hiding text blocks? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am doing a school project and i canĀ“t figure out how to "hide" some text blocks when the toggle switch is on and the opposite? Developing a windows 8 app. Thanks and btw. How do you make a collection from multiple text blocks(XAML)?
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
}
Assuming your control structure is fairly flat, you can get by using the Tag property on the TextBox. In your XAML, put some distinct value in the Tag field for each TextBox you want to make toggle-able, like the word 'CanToggle'. Then you can do something like
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
foreach (Control currentControl in this.Children)
{
if (currentControl.Tag == "CanToggle")
currentControl.Visible = !currentControl.Visible;
}
}
If your control collection is not flat, then you'll have to figure out how to dig recursively through the collection of controls to locate all the TextBox that you want to toggle. This answer may help.
Visual Studio Main Menu - Edit - Outlining - Toggle All Outlining: Ctrl+M, Ctrl+L
Personally, I use Ctrl+M to "collapse to defininitions" more than anything else though.

How to allow only valid values in a combobox? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
in C# with DotNet 4 i have a form with a combobox which is filled with values when starting the program.
Now user can dropdown and select one of the values.
But: It is also possible to write something new into the combobox-field.
Question: What can i do that it is NOT possible to write something which is not part of the list?
Thanks
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList".
It can be done by simply assigning a property to combobox .DropDownStyle = ComboBoxStyle.DropDownList. but, this property do not allow to edit text. means you have to select item either by mouse or by up/down arrow key. You cannot filter result by selecting this property. if you wish to filter result but don't allow to accept invalid value then you can do this by writing some code in cmb_Validating event
private void cmb_Validating(object sender, CancelEventArgs e)
{
if (cmb.SelectedValue == null && cmb.Text != string.Empty)
e.Cancel=true;
}

Categories