Ich benötige es und es lässt sich ja auch realisieren.
Ich hab hier mal den Teil meines Projektes, der mir Probleme macht (Designer in der nächsten Nachricht).
Wenn man einen Buton klickt, eine andere Zeile markiert und den anderen Button klickt, ist das Problem zu erkennen.
Form1.vb:
Public Class Form1
Private Sub Form1_Shown(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Shown
Call Update_dgv()
End Sub
Private Sub Update_dgv()
Dim odgv As DataGridView = Me.dgv
Try
odgv.Columns.Clear()
odgv.Rows.Clear()
odgv.Columns.Add("TEST", "TEST- Eintrag")
odgv.Columns(0).Width = odgv.Width - _
SystemInformation.VerticalScrollBarWidth
odgv.Rows.Add("Berlin")
odgv.Rows.Add("Wittenberg")
odgv.Rows(1).DefaultCellStyle.BackColor = Color.Red
odgv.Rows.Add("München")
odgv.Rows.Add("Zürich")
Catch
MsgBox(Err.Description)
End Try
End Sub
Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdTest.Click
Call Update_dgv()
End Sub
Private Sub cmdTest1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdTest1.Click
Dim odgv As DataGridView = Me.dgv
Try
odgv.Columns.Clear()
odgv.Rows.Clear()
odgv.Columns.Add("TEST", "TEST- Eintrag")
odgv.Columns(0).Width = odgv.Width - _
SystemInformation.VerticalScrollBarWidth
odgv.Rows.Add("Wittenberg")
odgv.Rows.Add("Berlin")
odgv.Rows(1).DefaultCellStyle.BackColor = Color.Red
odgv.Rows.Add("Zürich")
odgv.Rows.Add("München")
Catch
MsgBox(Err.Description)
End Try
End Sub
Private Sub dgv_RowPostPaint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles _
dgv.RowPostPaint
Call drawRectOnDgv(Me.dgv, 3, Color.Blue, e)
End Sub
Private Sub drawRectOnDgv(ByVal oDgv As DataGridView, ByVal lineWidth As _
Short, ByVal lineColor As Color, ByVal e As _
DataGridViewRowPostPaintEventArgs)
Dim rect As Rectangle
Dim iWidth As Integer = 0
Try
If oDgv.Rows(e.RowIndex).Selected Then ' ist die Zeile selektiert?
rect = oDgv.GetRowDisplayRectangle(e.RowIndex, False) ' das
' Rechteck der aktuellen Zeile
' Rechteck für den Rahmen erzeugen
'If oDgv.Controls(1).Visible = True Then iWidth = oDgv.Width - (
' iScrollBarWidth + iDgvWidthDifferenz) Else iWidth = oDgv.Width
iWidth = oDgv.Width - SystemInformation.VerticalScrollBarWidth
Dim rec As Rectangle = New Rectangle(1, rect.Y, iWidth, _
rect.Height - 1)
' Zeichnen des Rahmens
ControlPaint.DrawBorder(e.Graphics, rec, lineColor, lineWidth, _
ButtonBorderStyle.Solid, lineColor, lineWidth, _
ButtonBorderStyle.Solid, lineColor, lineWidth, _
ButtonBorderStyle.Solid, lineColor, lineWidth, _
ButtonBorderStyle.Solid)
End If
Catch
MsgBox(Err.Description)
End Try
End Sub
End Class |