.NET Framework - Kontextmenü_.Visible_=_false;_funktioniert_nicht

Asked By Alexander Richter
06-May-10 10:38 AM
Hallo,
ich habe ein DataGridView mit einem Kontextmen? erstellt.

private void Form1_Load(object sender, EventArgs e) {
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
contextMenuStrip.Items.Add("Mache");

dataGridView1.ContextMenuStrip = contextMenuStrip;
}

Mit einem Button will ich das Kontextmen? unsichtbar setzen.
private void button1_Click(object sender, EventArgs e) {
dataGridView1.ContextMenuStrip.Visible = false;
}

Das funktioniert aber nicht!
Deaktivieren funktioniert :  dataGridView1.ContextMenuStrip.Enabled = false;

Was mache ich falsch mit .Visible = false;, oder welchen Sinn hat es?
Wie kann ich ansonsten das Kontextmen? deaktivieren?


Alexander
EventArgs
(1)
DataGridView
(1)
Button
(1)
Alexander Alexander
(1)
Load
(1)
Deaktivieren
(1)
Elementen
(1)
Richter
(1)
  Elmar Boye replied to Alexander Richter
06-May-10 11:20 AM
Hallo Alexander,


Weise dem ContextMenuStrip null zu, wenn Du keines sehen willst,
und Dein eigenes nur dann, wenn es angezeigt werden soll.


Visible, was von ToolStripDown vererbt wird, wirkt nicht bei einem
ContextMenuStrip, und ist nur wirksam bei untergeordneten Elementen.

Gru? Elmar
help
KB / cs / event_fundamentals.aspx one should, if possible, use the generic framework supplied objects System.EventArgs of a class that derives from System.EventArgs." and support for it is built into the .NET Framework through the System.EventArgs class." - -and- - to), you should use one of the EventHandler delegates provided by the .NET following simple form button_click wants to raise an event that carries no data (so System.EventArgs.Empty) namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public delegate void EventHandler(object sender, EventArgs e); public event EventHandler MyEvent; public class MyEventArgs : System.EventArgs { } public void RaiseTheEvent(MyEventArgs eventArgs) { try { EventHandler handler = MyEvent; if (handler ! = null) { handler(this, eventArgs); } } catch { / / Handle exceptions here } } private void button1_Click(object sender, EventArgs e) { RaiseTheEvent(MyEventArgs.Empty); } } } . . .useless
marked with * below how would that / / Create a delegete public delegete void MyEventHandler(object sender, EventArgs e); / / Create an event member public event MyEventHandler MyEvent; / / Invoke the delegete within a method need to raise the event, as the following code demonstrates if(MyEvent ! = null) MyEvent((this, EventArgs.Empty) EventArgs e = new EventArgs(); if (handler ! = null) handler(this, e); C# Discussions NotImplementedException (1) Tell Tony Willem van Rumpt (1) EventHandler EventArgs (1) EventHandler (1) EventArgs (1) Class (1) Bit (1) Arne Arne Vajhøj (1) I do not see the * !?!? Arne mean something like this? - -- -- MyEvent = new MyEventHandler( (sender_, e_) = > { throw new NotImplementedException(); }); MyEvent.Invoke(this, EventArgs.Empty); - -- -- Or just. . . - -- -- if (MyEvent ! = null) { MyEvent.Invoke(this, EventArgs.Empty); } - -- -- In the book I read it says the following. How to raise an event
I am programming a function to process the result of an event OnSelectionChanged from a DataGridView. My concern is that I do not know the type of arguments I should use in this function for a cast to recover the information provided by the System.EventArgs value transmitted by the system in the following way : void gridView_SelectionChanged(object sender, System EventArgs e) { WhichType mydata = e as WhichType; } And generally, how can I know which type of ProgressChangedEventArgs (1) Visual Studio (1) ProgressEventArgs (1) CancelEventArgs (1) MouseEventArgs (1) EventHandler (1) GetHashCode (1) EventArgs (1) You look at the event declaration. The signature of the delegate type used to at least, for every example I know of) events using the EventHandler type, and the EventArgs object that is passed to your handler is always just of type EventArgs (and in fact, should always be the EventArgs.Empty instance???though your program should not rely on that). Since the event is raised other data to pass to the handler and thus no need for anything other than EventArgs itself. If some other sub-class of EventArgs is being used, then that type will
ListBox samt hämta alla djurtyper för vald djur kategori / / / < / summary> / / / / / / private void LstCategory_SelectedIndexChanged(object sender, EventArgs e) { lstAnimalType.Items.Clear(); lstAnimalType.Items.AddRange(new Category().GetMyValues(lstCategory.Text).ToArray()); } / / / <summary> / / / The Add button has been activated the following is done / / 1.Validate the user input. If error give Update GUI so the new added animal is displayed / / / < / summary> / / / / / / private void BtnAddAnimal_Click(object sender, EventArgs e) { if (!ValidateInput()) return; CategoryType category = (CategoryType)Enum.Parse(typeof(CategoryType), lstCategory.Text); EaterType eater false, foodMenuList, categoryInfo); UpdateGUI(); InitializeGUI(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message); } } / / / <summary> / / / The Change button has been activated do the following. / / 1.Validate the user input. if error give error Update GUI so the changed animal object is shown / / / < / summary> / / / / / / private void BtnAnimalChange_Click(object sender, EventArgs e) { if (selectedAnimal = = null) { MessageBox.Show("You must click a row in ListView before Changing that the removed animal object is no longer there / / / < / summary> / / / / / / private void BtnAnimalDelete_Click(object sender, EventArgs e) { if (selectedAnimal = = null) { MessageBox.Show("You must click a row in ListView before Deleting finns någon bild på detta djur erhålles ett meddelande / / / < / summary> / / / / / / private void LstAnimalType_SelectedIndexChanged(object sender, EventArgs e) { picAnimal.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; string imagePath = Path.Combine(Environment.CurrentDirectory, @". . \ . . \ Pictures on a row in ListView this evanhandler is called / / / < / summary> / / / / / / private void listViewAnimals_ItemActivate(object sender, EventArgs e) { ListView lw = (ListView)sender; string id = lw.SelectedItems[0].Text; selectedAnimal = animalManager.GetAnimalByID(id
Wie im DataGridView einzelne Zeilen deaktivieren? .NET Framework Hallo, ich will in einem DataGridView einzelne Zeilen deaktivieren, d.h sichtbar (grau) und nicht ausw?hlbar. Wie kann man das Deaktivieren realisieren? foreach (DataGridViewRow row in dataGridView1.Rows) { if (!isDeaktiviert) { row. ???????? } } Alexander C# - German Discussions DataTable (1 EventArgs (1) Class (1) DataGridView (1) Button (1) Color (1) ReadOnly (1) Load (1) Hallo Alexander, dgvClientStatus.Rows[1].ReadOnly = 3D true; dgvClientStatus.Rows[1].DefaultCellStyle.BackColor = 3D Color.LightGray; Sei