2011-08-02 11 views
0

データグリッドを埋めるために使用する2列とMatchCollectionを持つdatagridviewがあります。最初の列のデータグリッドにmatchcollectionの最初の一致を挿入し、次に2番目の列のmatchcollectionの2番目の値を挿入できます。その後、新しい行が作成され、再び開始されます。MatchCollectionをdatagridviewに挿入するC#

このグリッドビューにはデータがバインドされていないため、データグリッドに挿入されているmatchCollectionがテーブルの他のものを上書きしないようにする必要があります。これどうやってするの?

これは、あなたがカスタムGridViewの列を作成し、DataGridViewTextBoxCellから継承することができます

while (!sr.EndOfStream) 
        { 
         string line = sr.ReadLine(); 
         line = line.Trim(); 
         if (line.StartsWith("addTestingPageContentText")) 
         { 
          string temp; 
          string pattern = "\"([^\"]+)\""; 
          Regex r = new Regex(pattern); 
          MatchCollection regs = r.Matches(line); 

          foreach (Match reg in regs) 
          { 

           temp = reg.ToString(); 
           temp = temp.Replace("\"", ""); 

           int rowCount = contentTable_grd.Rows.Count - 1; 


         if (contentTable_grd.Rows[rowCount].Cells[0].Value == null) 
          contentTable_grd.Rows[rowCount].Cells[0].Value = temp; 
         else 
          contentTable_grd.Rows[rowCount].Cells[1].Value = temp; 


         contentTable_grd.Rows.Add(); 

          } 
         } 
        }   
+0

のWinFormやASP.NETを試してみてください? – Peyman

+0

@peyman winforms –

答えて

1

この

while (!sr.EndOfStream) 
      { 
       string line = sr.ReadLine(); 
       line = line.Trim(); 
       if (line.StartsWith("addTestingPageContentText")) 
       { 
        string temp; 
        string pattern = "\"([^\"]+)\""; 
        Regex r = new Regex(pattern); 
        MatchCollection regs = r.Matches(line); 


        object[] array1 = new object[2];      



        foreach (Match reg in regs) 
        { 

         temp = reg.ToString(); 
         temp = temp.Replace("\"", ""); 

         if (array1[0] == null) 
          array1[0] = temp; 
         else 
          array1[1] = temp; 
        } 

        if (regs.Count > 0) 
         contentTable_grd.Rows.Add(array1); 
       } 
      } 
関連する問題