2010-04-21 2 views
0

DataGridView에서 빈 줄마다 페인트 할 수 있습니까?DataGridView에서 빈 줄마다 페인트 할 수 있습니까?

예 :

123 | 444 | 555  
123 | 555 | 666 

333 | 555 | 666 

666 | 777 | 888 

이 될 것입니다 :

123 | 444 | 555  
123 | 555 | 666 
---------------  
333 | 555 | 666 
---------------  
666 | 777 | 888 

에서의 WinForm - 잘 모르겠어요 사전

+0

테두리를 고려해야 할 수도 있습니다. 이것은 힘든 일처럼 보입니다. 데이터가없는 행 안의 모든 셀 (일부 값이있는 숨겨진 열 하나라고 가정 함)은 사용자 정의 페인트해야합니다. –

답변

1

아주 가깝습니다. 귀하의 경우 행은 비어 있습니다. 당신은, 글꼴 등

alt text http://img72.imageshack.us/img72/6450/76236843.jpg

private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) 
    { 
     if (e.RowIndex == 2) 
     { 
      // Calculate the bounds of the row 
      int rowHeaderWidth = dataGridView1.RowHeadersVisible ? 
           dataGridView1.RowHeadersWidth : 0; 
      Rectangle rowBounds = new Rectangle(
       rowHeaderWidth, 
       e.RowBounds.Top, 
       dataGridView1.Columns.GetColumnsWidth(
         DataGridViewElementStates.Visible) - 
         dataGridView1.HorizontalScrollingOffset + 1, 
       e.RowBounds.Height); 

      // Paint the row 
      ControlPaint.DrawStringDisabled(e.Graphics, "- - - - - - - - - - - - - - - - - - - - - - - -", new Font("Times New Roman", 15f), Color.DarkGray, rowBounds, TextFormatFlags.Default); 
     } 
    } 

Form2_Load() 색상으로 좀 더 최적화 할 수 있습니다 - 그냥 그냥 재현 붙여 복사 할 수 있도록 코드를 완성 할 수 있습니다.

private void Form2_Load(object sender, EventArgs e) 
     { 
      this.dataGridView1.ColumnCount = 4; 
      this.dataGridView1.Columns[0].Name = "Recipe"; 
      this.dataGridView1.Columns[0].SortMode = 
       DataGridViewColumnSortMode.NotSortable; 
      this.dataGridView1.Columns[1].Name = "Category"; 
      this.dataGridView1.Columns[2].Name = "Main Ingredients"; 
      this.dataGridView1.Columns[3].Name = "Rating"; 

      // Hide the column that contains the content that spans 
      // multiple columns. 
      this.dataGridView1.Columns[2].Visible = false; 

      // Populate the rows of the DataGridView. 
      string[] row1 = new string[]{"Meatloaf", "Main Dish", 
      "1 lb. lean ground beef, 1/2 cup bread crumbs, " + 
      "1/4 cup ketchup, 1/3 tsp onion powder, 1 clove of garlic, " + 
      "1/2 pack onion soup mix, dash of your favorite BBQ Sauce", 
      "****"}; 
      string[] row2 = new string[]{"Key Lime Pie", "Dessert", 
      "lime juice, whipped cream, eggs, evaporated milk", "****"}; 
      string[] row3 = new string[]{"Orange-Salsa Pork Chops", 
      "Main Dish", "pork chops, salsa, orange juice, pineapple", "****"}; 
      string[] row4 = new string[]{"Black Bean and Rice Salad", 
      "Salad", "black beans, brown rice", "****"}; 
      string[] row5 = new string[]{"Chocolate Cheesecake", 
      "Dessert", "cream cheese, unsweetened chocolate", "***"}; 
      string[] row6 = new string[]{"Black Bean Dip", "Appetizer", 
      "black beans, sour cream, salsa, chips", "***"}; 
      object[] rows = new object[] { row1, row2, row3, row4, row5, row6 }; 
      foreach (string[] rowArray in rows) 
      { 
       this.dataGridView1.Rows.Add(rowArray); 
      } 
     } 
0

에서 C#

감사의 당신이 할 수있을 것입니다 경우 당신이 원하는 것을해라.하지만 나는 DataGridView의 RowPrePaint와 RowPostPaint 이벤트를 살펴볼 것을 제안한다. 또한 CellPainting 이벤트.

다음 링크는 도움이 될 수 있습니다 당신이 필요로 http://msdn.microsoft.com/en-us/library/85kxk29c.aspx

관련 문제