2014-06-30 10 views
6

मैं उन पंक्तियों को समूहबद्ध करना चाहता हूं जो DataGridView में समान नाम हैं, नीचे दिए गए विंडोज फॉर्म पर वह छवि है जिसे मैं कार्यान्वित करना चाहता हूं।डेटाग्रिड व्यू में समूह पंक्तियां

क्या किसी तीसरे पक्ष के उपकरण का उपयोग किए बिना नीचे कार्यान्वित करना संभव है?

sample

+0

के सौजन्य से नहीं, मानक नियंत्रण के साथ आसानी से ऐसा करने का कोई तरीका नहीं है। – MoonKnight

+0

@ किल्करम: हाँ, मुझे भी कोई समाधान नहीं मिला है। – Deeps

उत्तर

3

आप खड़ी सेल के बजाय पंक्ति के रूप में इस लेख DataGridView Grouping in C#/VB.NET: Two Recipes में विस्तार से बताया समूहीकरण विलय की MSFlexGrid के MergeCells संपत्ति की कार्यक्षमता का उपयोग की कोशिश कर सकते। इस उदाहरण में, शास्त्रीय क्षैतिज समूह पंक्तियों का उपयोग करने के बजाय, समूह से संबंधित पंक्तियां लंबवत रूप से विलय किए गए कोशिकाओं का उपयोग करके दृश्यमान रूप से जुड़ती हैं।

enter image description here

protected override void OnCellPainting(DataGridViewCellPaintingEventArgs args) 
{ 
    base.OnCellPainting(args); 

    args.AdvancedBorderStyle.Bottom = 
    DataGridViewAdvancedCellBorderStyle.None; 

    // Ignore column and row headers and first row 
    if (args.RowIndex < 1 || args.ColumnIndex < 0) 
    return; 

    if (IsRepeatedCellValue(args.RowIndex, args.ColumnIndex)) 
    { 
    args.AdvancedBorderStyle.Top = 
     DataGridViewAdvancedCellBorderStyle.None; 
    } 
    else 
    { 
    args.AdvancedBorderStyle.Top = AdvancedCellBorderStyle.Top; 
    } 
} 
+1

मुझे लगता है कि हम सीमा को हटाकर यहां केवल भ्रम पैदा कर रहे हैं। – Deeps

+1

लेकिन क्या आप इसे किसी तीसरे पक्ष के पुस्तकालयों/नियंत्रणों के बिना हासिल करना चाहते हैं? – chridam

+0

हाँ, मैं वही करना चाहता हूं लेकिन इसके बाद। मैं सभी समूह वस्तुओं की जांच के लिए एक चेकबॉक्स रखना चाहता हूं और कुछ ऑपरेशन करना चाहता हूं। इसलिए यह समाधान नहीं है, हालांकि आप सही हैं, हम छवि में प्रदर्शित होने के समान दिख सकते हैं। मदद के लिए धन्यवाद .. :) – Deeps

3

DataGridView जगह में

dgvProduct_CellFormatting Event 

If e.RowIndex > 0 And e.ColumnIndex = 0 Then 
       If dgvProduct.Item(0, e.RowIndex - 1).Value = e.Value Then 
        e.Value = "" 
       ElseIf e.RowIndex < dgvProduct.Rows.Count - 1 Then 
        dgvProduct.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White 
       End If 
End If 

में निम्न कोड सभी कार्य पूर्ण!

enter image description here

0

आनंद लें (चुने हुए) जवाब के पूरक के लिए, यहाँ पूर्ण कोड है। अनियमित विचार डेटाग्रिड व्यू क्लास को विस्तारित करने वाली कक्षा है।

public class GroupByGrid : DataGridView 
    { 

     protected override void OnCellFormatting(
      DataGridViewCellFormattingEventArgs args) 
     { 
      // Call home to base 
      base.OnCellFormatting(args); 

      // First row always displays 
      if (args.RowIndex == 0) 
       return; 


      if (IsRepeatedCellValue(args.RowIndex, args.ColumnIndex)) 
      { 
       args.Value = string.Empty; 
       args.FormattingApplied = true; 
      } 
     } 

     private bool IsRepeatedCellValue(int rowIndex, int colIndex) 
     { 
      DataGridViewCell currCell = 
       Rows[rowIndex].Cells[colIndex]; 
      DataGridViewCell prevCell = 
       Rows[rowIndex - 1].Cells[colIndex]; 

      if ((currCell.Value == prevCell.Value) || 
       (currCell.Value != null && prevCell.Value != null && 
       currCell.Value.ToString() == prevCell.Value.ToString())) 
      { 
       return true; 
      } 
      else 
      { 
       return false; 
      } 
     } 

     protected override void OnCellPainting(
      DataGridViewCellPaintingEventArgs args) 
     { 
      base.OnCellPainting(args); 

      args.AdvancedBorderStyle.Bottom = 
       DataGridViewAdvancedCellBorderStyle.None; 

      // Ignore column and row headers and first row 
      if (args.RowIndex < 1 || args.ColumnIndex < 0) 
       return; 

      if (IsRepeatedCellValue(args.RowIndex, args.ColumnIndex)) 
      { 
       args.AdvancedBorderStyle.Top = 
        DataGridViewAdvancedCellBorderStyle.None; 
      } 
      else 
      { 
       args.AdvancedBorderStyle.Top = AdvancedCellBorderStyle.Top; 
      } 
     } 
    } 

source social.msdn.microsoft

संबंधित मुद्दे