Bonjour,
J'ai créer un controle utilisateur qui hérite du datagridview. Une des fonctionnalité du controle est que lorsque l'utilisateur sélectionne une cellule d'une colonne bien précise la datagridviewcell est changé en DataGridViewComboBoxCell. et lorsqu'il quitte la cellule on remet la cellule comme au départ mais avec la nouvelle valeur. Cela permet la sélection de valeur bien précise. Cela fonctionne bien mais je me suis rendu compte d'une anomalie. Lorsque la cellule cliqué est situé un index de ligne identique à l'index de colonne, il y a une exception. ([3,3], [4,4] [5,5] ... ) :
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
Le fonctionnement:
Dans mon controle sur l'événement OnCellEnter j'appelle la fonction pour changer la cellule en combobox
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
protected override void OnCellEnter(DataGridViewCellEventArgs e)
{
    ChangerTextEnComboBox(e.ColumnIndex, e.RowIndex);           
    base.OnCellEnter(e);
}
 
public void ChangerTextEnComboBox(int _colonne, int _ligne)
{
	GrilleDonneesCelluleValeur source = base[_colonne, _ligne] as GrilleDonneesCelluleValeur;
	DataGridViewComboBoxCell cellule = new DataGridViewComboBoxCell();
 
	//remplir le combobox
	for (int i = 0; i < Enum.GetValues(typeof(ENUM_COTE)).Length; i++)
		cellule.Items.Add(...);
 
	//affectation des valeurs
	cellule.Value = source.Value;
	cellule.Tag = source;
	base[_colonne, _ligne] = cellule;
}
Le problème survient comme je l'ai dit quand e.ColumnIndex et e.RowIndex sont égale et sur la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
base[_colonne, _ligne] = cellule;
Voici le détail de l'erreur si c'est utile :
System.InvalidOperationException was unhandled
Message="Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.ResetCurrentCell()
at System.Windows.Forms.DataGridView.OnReplacingCell(DataGridViewRow dataGridViewRow, Int32 columnIndex)
at System.Windows.Forms.DataGridViewCellCollection.set_Item(Int32 index, DataGridViewCell value)
at System.Windows.Forms.DataGridView.set_Item(Int32 columnIndex, Int32 rowIndex, DataGridViewCell value)
at CreateurXml.GrilleDonnees.ChangerTextEnComboBox(Int32 _colonne, Int32 _ligne)
at CreateurXml.GrilleDonnees.OnCellEnter(DataGridViewCellEventArgs e)
at System.Windows.Forms.DataGridView.OnCellEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
Merci de m'éclairer la vue