首页 > 代码库 > Linq使用小记之Group By

Linq使用小记之Group By

private void cmbStore_SelectedIndexChanged(object sender, EventArgs e)        {            DataTable vDt = ParamClass.ChargDt;            var q = from b in vDt.AsEnumerable() group b by new { storeid = b["STOREID"], charg = b["charg"] } into g select new { g.Key.storeid, g.Key.charg };            if (q != null && q.Count() > 0)            {                for (int i = 0; i < gridPurchaseOrderDetail.Rows.Count; i++)                {                    (gridPurchaseOrderDetail.Rows[i].Cells["CHARG"] as DataGridViewComboBoxCell).DataSource = q.ToList();                    (gridPurchaseOrderDetail.Rows[i].Cells["CHARG"] as DataGridViewComboBoxCell).ValueMember = "charg";                    (gridPurchaseOrderDetail.Rows[i].Cells["CHARG"] as DataGridViewComboBoxCell).DisplayMember = "charg";                    (gridPurchaseOrderDetail.Rows[i].Cells["CHARG"] as DataGridViewComboBoxCell).Value = http://www.mamicode.com/q.ElementAt(0).charg;                     getStockNum(i);                }            }        }

 

Linq使用小记之Group By