2014-01-15 22 views
0

我想要做的是收集DocNumber的referrence數據庫,並把它在DataGrid記錄,有時是單對多一個DataGrid。取決於如何通過檢索。這裏是我下面的功能代碼:如何增加價值,有一個組合框列

internal void SelectDetailsRecord(string p) 
{ 
    SFCDataContext SFC = new SFCDataContext(); 
    try 
    { 
     var DetailsRec = SFC.Sales_OrderFormDetails.Where(w => w.OrderDocNum == p) 
      .Select(t => new { 
        Ord = t.OrderDocNum, 
        Line = t.LineNumber, 
        Vcode = t.VariantCode, 
        Vdesc = t.VariantDesc, 
        Icode = t.Itemnmbr, 
        Idesc = t.ItemDesc, 
        Qty = t.Quantity, 
        UofM = t.UofM, 
        Kgs = t.KgsPerBag, 
        Post = t.Posted 
      }); 
     int count = 0; 
     foreach (var r in DetailsRec) 
     { 
      decimal TotalKgs = Convert.ToDecimal(r.Qty) * Convert.ToDecimal(r.Kgs); 
      string[] row = 
      { 
       r.Qty.ToString(), 
       r.Icode, 
       r.Idesc, 
       r.UofM, 
       r.Vcode, 
       r.Vdesc, 
       r.Kgs.ToString(), 
       TotalKgs.ToString(), 
       r.Line.ToString() 
      }; 

      //DataGridView1.Rows.Add(row); <-- Tried this one but returns me an error statement. 

      DataGridView1.Rows[count].Cells[0].Value = row[0]; 
      DataGridView1.Rows[count].Cells[1].Value = row[1]; <-- this Part here is the combo box column 
      DataGridView1.Rows[count].Cells[2].Value = row[2]; 
      DataGridView1.Rows[count].Cells[3].Value = row[3]; 
      DataGridView1.Rows[count].Cells[4].Value = row[4]; 
      DataGridView1.Rows[count].Cells[5].Value = row[5]; 
      DataGridView1.Rows[count].Cells[6].Value = row[6]; 
      DataGridView1.Rows[count].Cells[7].Value = row[7]; 
      DataGridView1.Rows[count].Cells[8].Value = row[8]; 

      count++; 
     }     
    } 
    catch (Exception) { } 
    SFC.Connection.Close(); 
} 

有沒有一種方法我可以把記錄的值到DataGrid中的ComboBox就像把一個價值在這樣的組合框:「ComboBox.Text =值;」請幫助如果anytone有想法。

+0

因此'DataGridView1.Rows [count] .Cells [1]'包含一個ComboBox,其DataSource是行[1]? – dursk

+0

行[1]是我從一個數據庫LINQ查詢檢索值我將它放在一個字符串,所以我可以把1列等於一個DataGrid列1行數據的。但每個DataGrid行包含1個組合框類型的單元格[1],其他只是文本框。 – John

+0

顯示綁定網格組合框的代碼。 –

回答

0

此代碼必須在這個問題上的工作:

DataGridView1.Rows[count].Cells[1].Value = Convert.ToString(row[1]); 

你必須object值轉換爲stringGridComboBox設定值。還請確保row[1]的值存在於集合GridComboBox

+0

它仍然沒有工作,它說關於它的指數的東西,但我檢查它在組合框中選擇存在相同的數據記錄,以便它不應該是一個-1選擇。但它仍然表示,其-1 – John

+0

@約翰[1]'已被它是哪種類型的值'行'的或SelectedValue''SelectedIndex'? –