Why can't I see the DataGridViewRow added to a DataGridView?

前端 未结 3 766
温柔的废话
温柔的废话 2021-01-13 02:02

I am trying to show rows in a DataGridView.

Here\'s the code:

foreach (Customers cust in custList)
            {
                string[] rowValues =         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 02:18

    List custList = GetAllCustomers();
                dataGridView1.Rows.Clear();
    
                foreach (Customer cust in custList)
                {
                    //First add the row, cos this is how it works! Dont know why!
                    DataGridViewRow R = dataGridView1.Rows[dataGridView1.Rows.Add()];
                    //Then edit it
                    R.Cells["Name"].Value = cust.Name;
                    R.Cells["Address"].Value = cust.Address;
                    R.Cells["Phone"].Value = cust.PhoneNo;
                    //Customer Id is invisible but still usable, like,
                    //when double clicked to show full details
                    R.Tag = cust.IntCustomerId;
                }
    

    http://aspdiary.blogspot.com/2011/04/adding-new-row-to-datagridview.html

提交回复
热议问题