Autor Beitrag
MarcinD
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

Windows 7 Ultimate (64Bit)
VS2008 Prof. - C#
BeitragVerfasst: Fr 14.01.11 18:12 
Hallo zusammen,

ich habe in einem Datagridview eine Combobox, die ich gerne aufklappen möchte, wenn die Zelle editiert wird.
Leider verhält sich das Programm so, dass es immer die vorher bearbeitetet Zelle öffnet.

Bsp.:
3 Spalten Jahr / Monat / Tag
Monat ist die Combobox. Wenn ich jetzt ein Jahr eingebe und dann die Eingabe im Monat anfange, dann versucht er die Textbox von Jahr aufzuklappen. Dort blinkt kurz was auf, dass die Zeilenanzahl der Combobox hat und verschwindet wieder.

Wenn man jetzt eine Monat bearbeitet hat und auf die nächste Zeile geht um den Monat zu editieren, dann wird die Auswahl aufgeklappt, aber in dem Feld eine Zeile höher, also da wo man vorher bearbeitet hat.

Das Aufklappen, habe ich im Netz gefunden und mache es so:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
        private void dgPlanmassnahmen_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            {
                DataGridViewComboBoxEditingControl ctrl = e.Control as DataGridViewComboBoxEditingControl;
                if (ctrl != null)
                {
                    ctrl.DroppedDown = true;
                }
            }
        }


Weiß jemand, was daran verkehrt ist?
Habe gerade nochmal gemerkt, dass es auch beim klicken auf das ComboBox Feld zum Aufklappen so ist. Also wenn man das Feld mit dem umgedrehten Dreieck klickt um die Auswahl zu öffnen.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Fr 14.01.11 18:56 
Probiere mal
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
ComboBox combo = e.Control as ComboBox;
if (combo != null)
{
  combo.DroppedDown = true;
}

so steht es auch im Beispiel zu DataGridViewEditingControlShowingEventArgs.Control
MarcinD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

Windows 7 Ultimate (64Bit)
VS2008 Prof. - C#
BeitragVerfasst: Fr 14.01.11 22:16 
nein, leider bringt das auch nichts. Der Effeckt bleibt der gleiche.

Hier kann man es sehen. Als letztes habe ich die Combobox in der 4ten Zeile geöffnet und dann anschliessend die in der ersten Zeile angeklickt. Es wird die Liste der 4ten zeile geöffnet.

img20.imageshack.us/i/datagridview.jpg/
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 15.01.11 02:45 
Dann fällt mir nur noch das DataGridView.CellBeginEdit-Ereignis ein, in der du dann auf das DataGridViewComboBoxEditingControl zugreifen könntest (wobei du dann mal prüfen solltest, welches der beiden Ereignisse zuerst aufgerufen wird).
Intern gibt es ja nur genau ein gehostetes EditingControl, daher scheint noch immer das alte Control aktiv zu sein (und bei den DataGridViewEditingControlShowingEventArgs übergeben zu werden) - sehr merkwürdig!?!
MarcinD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

Windows 7 Ultimate (64Bit)
VS2008 Prof. - C#
BeitragVerfasst: Sa 15.01.11 10:36 
Leider komme ich in em Ereignis nicht an das Control dran.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
        private void dgPlanmassnahmen_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            ComboBox combo = e.control as ComboBox;
            if (combo != null)
            {
                combo.DroppedDown = true;
            }
        }


der emckert mir da das e.Control an. ".... enthält keine Definition von ...." Muss ich da noch was ändern?
MarcinD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

Windows 7 Ultimate (64Bit)
VS2008 Prof. - C#
BeitragVerfasst: Sa 15.01.11 10:57 
Ahh hab was gefunden.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
    private void dgPlanmassnahmen_CellEnter(object sender, DataGridViewCellEventArgs e)
    {
      if (dgPlanmassnahmen.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn)
      {
        dgPlanmassnahmen.CurrentCell = (DataGridViewComboBoxCell)dgPlanmassnahmen[e.ColumnIndex, e.RowIndex];
        dgPlanmassnahmen.BeginEdit(true);
        ((DataGridViewComboBoxEditingControl)dgPlanmassnahmen.EditingControl).DroppedDown = true;
      }
    }


Funktioniert zwar beim Enter der Zelle, geht aber auch ganz gut. Ist zu 95 % Gut. Wenn mir noch jemand sagen könnte, wie ich beim Editieren (Also Tastendruck) das Ding aufmache, dann wäre ich super zufrieden.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 15.01.11 13:04 
Ja, so wie in deinem CellEnter-Ereignis meinte ich es für das CellBeginEdit-Ereignis, also
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
private void dgPlanmassnahmen_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
    if (dgPlanmassnahmen.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn)
    {
        ((DataGridViewComboBoxEditingControl)dgPlanmassnahmen.EditingControl).DroppedDown = true;
    }
}