关于DataGridView绑定数据源后未设置的列不显示

把datagridview 数据源转换为绑定的数据源

    public class PlanInfo
    {
        /// <summary>
        /// 计划ID
        /// </summary>
        public int a { get; set; }
        /// <summary>
        /// 序号
        /// </summary>
        public int b { get; set; }
        /// <summary>
        /// 发车
        /// </summary>
        public string c { get; set; }

    }

List<PlanInfo> planInfos1 = new List<PlanInfo>();
dataGridview 绑定planInfos1,显示列为计划ID,序号。现访问其他列的数据
 List<PlanInfo> ps = dataGridview.DataSource as List<PlanInfo>;
                PlanInfo p = ps[e.RowIndex];

                    this.c = p.a;
                    this.c = p.c;
                 
       private void dataGridview_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e)
        {
            foreach (DataGridViewRow dr in this.dgvOnVehicle.Rows)
            {
                dr.Selected = false;
            }
            this.dataGridview.Rows[e.RowIndex].Selected = true;
            DataGridView dgv = (DataGridView)sender;
            List<PlanInfo> ps = dgv.DataSource as List<PlanInfo>;
            if (ps != null)
            {
                PlanInfo p = ps[e.RowIndex];
                if (p == null) return;


                    planInfoMenu = p;

                    this.a = p.a;
                    this.b = p.b;
                    this.c = p.c;
                  
                }
                catch (Exception ex)
                {
                }
            }
        }
               

你可能感兴趣的:(datagridview)