2017-12-07 1 views
0

Ich habe ein seltsames Problem mit einem DataGridView auf einem WinForm. Ich kann alle Spalten mit der Maus skalieren, aber ganz rechts kann ich nur verkleinern und nicht vergrößern. DataGridView am weitesten rechts Spalte Benutzer Größe nicht funktioniert

Weiß jemand, wie man das löst?

+0

Haben Sie die Standardeinstellungen von datagridview geändert? bcuz kann ich ohne Probleme mit erhöhen. Überprüfen Sie ColumnHeader ../ RowHeader .. Eigenschaften. Versuchen Sie, das Gitter zu löschen und ein neues hinzuzufügen, um zu sehen, ob dieses Problem auftritt –

Antwort

1

Dies ist von Entwurf. Wenn Sie die Maustaste gedrückt halten, wird die Maus erfasst und kann den Client-Bereich nicht verlassen, wodurch die Größenänderung blockiert wird. Du musst es tun.

Ich habe versucht, P/Invoke, um das Capture freizugeben.
Sehen Sie, ob dies für Sie funktioniert (natürlich, wenn ein AutoSize-Modus eingestellt ist, wird nichts passieren).

private bool IsLastColumn = false; 
private bool IsMouseDown = false; 
private int MouseLocationX = 0; 

private void dataGridView1_MouseDown(object sender, MouseEventArgs e) 
{ 
    int _LastColumnIndex = dataGridView1.Columns.Count - 1; 
    //Check if the mousedown is contained in last column boundaries 
    //In the middle of it because clicking the divider of the row before 
    //the last may be seen as inside the last too. 
    Point _Location = new Point(e.X - (dataGridView1.Columns[_LastColumnIndex].Width/2), e.Y); 
    if (dataGridView1.GetColumnDisplayRectangle(_LastColumnIndex, true).Contains(_Location)) 
    { 
     //Store a positive checks and the current mouse position 
     this.IsLastColumn = true; 
     this.IsMouseDown = true; 
     this.MouseLocationX = e.Location.X; 
    } 
} 

private void dataGridView1_MouseMove(object sender, MouseEventArgs e) 
{ 
    //If it's the last column and the left mouse button is pressed... 
    if ((this.IsLastColumn == true) && (this.IsMouseDown == true) && (e.Button == System.Windows.Forms.MouseButtons.Left)) 
    { 
     //... calculate the offset of the movement. 
     //You'll have to play with it a bit, though 
     int _ColumnWidth = dataGridView1.Columns[dataGridView1.Columns.Count - 1].Width; 
     int _ColumnWidthOffset = _ColumnWidth + (e.X - this.MouseLocationX) > 0 ? (e.X - this.MouseLocationX) : 1; 
     //If mouse pointer reaches the limit of the clientarea... 
     if ((_ColumnWidthOffset > -1) && (e.X >= dataGridView1.ClientSize.Width - 1)) 
     { 
     //...resize the column and move the scrollbar offset 
     dataGridView1.HorizontalScrollingOffset = dataGridView1.ClientSize.Width + _ColumnWidth + _ColumnWidthOffset; 
     dataGridView1.Columns[dataGridView1.Columns.Count - 1].Width = _ColumnWidth + _ColumnWidthOffset; 
     } 
    } 
} 

private void dataGridView1_MouseUp(object sender, MouseEventArgs e) 
{ 
     this.IsMouseDown = false; 
     this.IsLastColumn = false; 
} 
+0

Vielen Dank für Ihre Hilfe, das hat mein Problem gelöst! – user2332131

Verwandte Themen