您的位置:首页 > 其它

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

2011-07-21 23:30 1286 查看
把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)

{

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐