Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 private void mainBindingSource_CurrentChanged( object sender, EventArgs e ) { BindingSource bs = sender as BindingSource; // [...] btnDelete.Enabled = bs.Current != null; } private void btnDelete_Click( object sender, EventArgs e ) { mainBindingSource.RemoveCurrent(); MAJStatusLabel(); }
J'ai un problème à ce niveau là...
LE bouton Delete ne doit pas être activable quand il n'y a aucun champ dans le DataGridView (par extension, dans le BindingSource).
ça marche très bien quand on démarre une nouvelle liste (RAZ du bindingSource)
MAis si on supprime le dernier champ en appuyant sur le bouton Delete...
le RemoveCurrent appelle l'évènement CurentChanged
et là, ça passe pas...
car on désactive le bouton Delete alors que l'on est encore dans l'appel de celui-ci...
l'erreur est du style:
Ce qui est bizarre, c'est que l'erreur est un indexOutOfRange (-1) par rapport au DataGridView...************** Texte de l'exception **************
System.IndexOutOfRangeException: L'index -1 n'a pas de valeur.
à System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
à System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e)
à System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
à System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
à System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick, Boolean clearSelection, Boolean forceCurrentCellSelection)
à System.Windows.Forms.DataGridView.MakeFirstDisplayedCellCurrentCell(Boolean includeNewRow)
à System.Windows.Forms.DataGridView.OnEnter(EventArgs e)
à System.Windows.Forms.ContainerControl.UpdateFocusedControl()
J'ai fait divers test et j'en ai conclu que c'est la désactivation du bouton Delete qui pose problème...
JE sais pas trop comment réglé ce problème :/ .
Et si quelq'un peut m'expliquer le pourquoi de l'exception également, ça m'intéresse
merci
Partager