개발중인 컨트롤에 대해 DataGridView 컨트롤을 상속하고 있습니다. 목표는 런타임에 변경할 수있는 객체 상태를 나타내는 각 행 색상을 만드는 것입니다. 내 개체가 Observable 디자인 패턴을 구현합니다. 그래서 내 자신의 DataGridViewRow 클래스를 개발하고 Observer 패턴을 구현하고 행을 객체를 관찰하기로 결정했습니다. 나는 인 selectionchanged 이벤트를 선택한 행에 내 UpdateColors 메서드를 호출런타임시 DataGridview 행 색상 변경
public void UpdateColors(int state)
{
DefaultCellStyle.BackColor = m_ETBackColors[state];
DefaultCellStyle.ForeColor = m_ETForeColors[state];
}
나는 색상 변경을 테스트하는 순간 내 개체를 관찰, 그래서 수 없습니다 :이 클래스에서 , 나는이 방법을 가지고있다.
이제 작동하지 않습니다. 이전에 선택한 행이 파란색으로 유지되면 (선택한 경우처럼) 스크롤 할 때 셀 텍스트가 쌓입니다. DataGridView.Refresh()를 호출했지만 그 중 하나가 작동하지 않습니다.
데이터 원본에 바인딩되지 않은 datagridview를 추가해야합니다. 런타임 전에 얼마나 많은 열을 가지고 있는지 직접 알지 못하므로 수동으로 피드를 제공합니다.
누구든지 내가 뭘 잘못하고 있다고 말할 수 있습니까?
public void UpdateColors(int state)
{
DefaultCellStyle.BackColor = System.Drawing.Color.Yellow;
DefaultCellStyle.ForeColor = System.Drawing.Color.Black;
}
을하지만이 작동하지 않습니다 :
========== 업데이트 ==========
이 작동
public void UpdateColors(int state)
{
DefaultCellStyle.BackColor = m_ETBackColors[nEtattech];
DefaultCellStyle.ForeColor = m_ETForeColors[nEtattech];
}
와
:
System.Drawing.Color[] m_ETBackColors = new System.Drawing.Color[] { };
System.Drawing.Color[] m_ETForeColors = new System.Drawing.Color[] { };
에는 배열 오버 플로우가 없습니다 : 그들은 생성자 매개 변수입니다.
가 이미 UpdateColors 내 행에 대한 사용자 정의 색상 속성을 설정하고 내 데이터 그리드의 CellFormatting 이벤트를 사용하여,이 시도는 하지만, 문제가 해결되지 않았다 '개인 무효 DataGridViewEtat_Technique_CellFormatting (객체 송신자 System.Windows.Forms.DataGridViewCellFormattingEventArgs E) { DataGridViewTechnicalStateRow 행 행 = [e.RowIndex] DataGridViewTechnicalStateRow 등; row.DefaultCellStyle.BackColor = row.BCL; row.DefaultCellStyle.ForeColor = row.FCL; }' – Rifu