행 System.Windows.Forms.DataGrid
의 한 셀 내용을 기반으로의 전체 행에 색상을 지정하고 싶습니다 . DataGrid의 -Property 또는 DataGridTextBoxColumn (또는 이와 유사한) 의 -Property
가 없기 때문에 그렇게 할 수있는 방법을 찾을 수 없습니다 . 인터넷에서 솔루션을 검색하는 것도 지금까지 도움이되지 않았습니다. 로 전환 은 안타깝게도 옵션이 아닙니다..Rows
.Row
DataGridView
따라서 질문은 남아 있습니다. DataGrid 행의 색상을 어떻게 변경할 수 있습니까?
이 링크 (@Monty 제공) 덕분에 문제를 해결할 수있었습니다.
모든 셀을 자체적으로 포맷해야하므로 SetCellFormat
모든 열의 이벤트에 연결해야합니다 .
AddHandler column.SetCellFormat, AddressOf FormatGridRow
EventHandler에서 예를 들어 같은 행의 다른 열의 셀 값을 확인하고 그에 따라 현재 셀의 색상을 변경할 수 있습니다. 행의 모든 셀이 이러한 방식으로 형식화되면 행 전체가 형식화 된 것처럼 보입니다.
Private Sub FormatGridRow(ByVal sender As Object, ByVal e As DataGridFormatCellEventArgs)
Dim Cell As DataGridColumnStyle = sender
Dim ColumnStyles As GridColumnStylesCollection = Cell.DataGridTableStyle.GridColumnStyles
Dim columnIndex As Integer = ColumnStyles.IndexOf(ColumnStyles.Item("ColumnName"))
If Cell.DataGridTableTableStyle.DataGrid(e.Row, columnIndex).ToString() = "SomeValue" Then
e.BackBrush = New SolidBrush(Color.Red) 'this does only change the Cell`s background
End If
End Sub
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다