datagridview赋值了但是在页面没有显示

qq_30803751 2016-08-27 12:05:50
代码如下:
dgvPolyLine.Rows[i].Cells[0].Value = UserControl5.DxfTab.Rows[i][0];
dgvPolyLine.Rows[i].Cells[1].Value = UserControl5.DxfTab.Rows[i][1];
dgvPolyLine.Rows[i].Cells[2].Value = UserControl5.DxfTab.Rows[i][2];
dgvPolyLine.Rows[i].Cells[3].Value = UserControl5.DxfTab.Rows[i][3];
dgvPolyLine.Rows[i].Cells[4].Value = UserControl5.DxfTab.Rows[i][4];
dgvPolyLine.Rows[i].Cells[5].Value = UserControl5.DxfTab.Rows[i][5];



赋的值我打印过,有数据。但是页面显示不了
...全文
709 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
是咬金哥哥呀 2020-08-20
  • 打赏
  • 举报
回复
如果确定datarow一定有值就CopyToDataTable这个方法,没有的话就判断没值不赋值
是咬金哥哥呀 2020-08-20
  • 打赏
  • 举报
回复
如果要解决的话,就是把datarow[]的值放到一个datatable,然后直接把datatable赋值给datagridview就行
飞天凤凰601 2016-08-29
  • 打赏
  • 举报
回复
数据绑定没有?
dianjixue1 2016-08-29
  • 打赏
  • 举报
回复
你现在是在窗体上拖了一个DataGridView,然后命名dgvPolyLine,并且给他手动的添加了列,然后后台又把这个DataGridView初始化了,有代码添加了列。 你现在要做的是 1.注销掉第一行 dgvPolyLine = new DataGridView(); 2.注销掉代码给dgvPolyLine 添加列的语句 for (int i = 0; i < UserControl5.DxfTab.Columns.Count; i++) { dgvPolyLine.Columns.Add(new DataGridViewTextBoxColumn()); } 最后的代码变为

  //dgvPolyLine = new DataGridView();
            dgvPolyLine.ReadOnly = true;
            this.dgvPolyLine.AutoGenerateColumns = false;
            //this.dgvPolyLine.DataSource = UserControl5.DxfTab;
            //for (int i = 0; i < 6; i++)
            //{
            //    dgvPolyLine.Columns.Add(new DataGridViewTextBoxColumn());

            //}
            for (int i = 0; i < 1; i++)
            {

                this.dgvPolyLine.Rows.Add(new DataGridViewRow());
                dgvPolyLine.Rows[i].Cells[0].Value = "11";
                dgvPolyLine.Rows[i].Cells[1].Value = "12";
                dgvPolyLine.Rows[i].Cells[2].Value = "13";
                dgvPolyLine.Rows[i].Cells[3].Value = "14";
                dgvPolyLine.Rows[i].Cells[4].Value = "15";
                dgvPolyLine.Rows[i].Cells[5].Value = "16";
                //MessageBox.Show(dgvPolyLine.Rows[i].Cells[0].Value.ToString());
            }
baidu_34633664 2016-08-29
  • 打赏
  • 举报
回复
弱弱的问一声 dgvPolyLine = new DataGridView(); 之后,有没有 control.add(dgvPolyLine) 然后设置它的size location 理论上,看你 代码的意思是,新建了这个datagridview,数据也是有更新了 但是 这个 datagridview 没有location 和SIZE ,以及属于哪个窗体,所以你看不到
巴士上的邂逅 2016-08-29
  • 打赏
  • 举报
回复
把DataGridview删掉重新拖一个
qq_30803751 2016-08-28
  • 打赏
  • 举报
回复
引用 10 楼 yuankaiwsl 的回复:
你的DataGridview是在界面上拖过去的还是代码里写的? 上边代码中 dgvPolyLine = new DataGridView();是怎么回事?
界面拖进去的,我把你说的那句去了,一直提示未将引用设置到对象的实例。 列是我在界面定义好的,使用this.dgvPolyLine.Rows.Add(1);添加一行也报上面的错。
巴士上的邂逅 2016-08-27
  • 打赏
  • 举报
回复
你的DataGridview是在界面上拖过去的还是代码里写的? 上边代码中 dgvPolyLine = new DataGridView();是怎么回事?
qq_30803751 2016-08-27
  • 打赏
  • 举报
回复
dgvPolyLine = new DataGridView();
dgvPolyLine.ReadOnly = true;
this.dgvPolyLine.AutoGenerateColumns = false;
//this.dgvPolyLine.DataSource = UserControl5.DxfTab;
for (int i = 0; i < UserControl5.DxfTab.Columns.Count; i++)
{
dgvPolyLine.Columns.Add(new DataGridViewTextBoxColumn());

}
for (int i = 0; i < UserControl5.DxfTab.Rows.Count; i++)
{

this.dgvPolyLine.Rows.Add(new DataGridViewRow());
dgvPolyLine.Rows[i].Cells[0].Value = UserControl5.DxfTab.Rows[i][0];
dgvPolyLine.Rows[i].Cells[1].Value = UserControl5.DxfTab.Rows[i][1];
dgvPolyLine.Rows[i].Cells[2].Value = UserControl5.DxfTab.Rows[i][2];
dgvPolyLine.Rows[i].Cells[3].Value = UserControl5.DxfTab.Rows[i][3];
dgvPolyLine.Rows[i].Cells[4].Value = UserControl5.DxfTab.Rows[i][4];
dgvPolyLine.Rows[i].Cells[5].Value = UserControl5.DxfTab.Rows[i][5];
//MessageBox.Show(dgvPolyLine.Rows[i].Cells[0].Value.ToString());
}






qq_30803751 2016-08-27
  • 打赏
  • 举报
回复
不是这样,我之前用的datasource显示不了值,后来换为用循环逐一赋值。所以不会出现被覆盖这种说法吧应该
baidu_34633664 2016-08-27
  • 打赏
  • 举报
回复
打印的内容 来自与 datatable datagridview 里的的值改变后,又瞬间被datagridview.datasource=datatable 覆盖掉,成为空了 所以眼睛是看不到的 也许是这样
巴士上的邂逅 2016-08-27
  • 打赏
  • 举报
回复
只能上图上代码了
qq_30803751 2016-08-27
  • 打赏
  • 举报
回复
没有啊,我也没只有这一个datagridview,名字就是dgvPolyLine
巴士上的邂逅 2016-08-27
  • 打赏
  • 举报
回复
你看的没显示数据的DataGridview不是dgvPolyLine
qq_30803751 2016-08-27
  • 打赏
  • 举报
回复
我之前用datagridview.datasource=datatable。datatable有数据,但是datagridview显示不了数据。 我又改为 for (int i = 0; i < UserControl5.DxfTab.Rows.Count; i++) { this.dgvPolyLine.Rows.Add(new DataGridViewRow()); dgvPolyLine.Rows[i].Cells[0].Value = UserControl5.DxfTab.Rows[i][0]; dgvPolyLine.Rows[i].Cells[1].Value = UserControl5.DxfTab.Rows[i][1]; dgvPolyLine.Rows[i].Cells[2].Value = UserControl5.DxfTab.Rows[i][2]; dgvPolyLine.Rows[i].Cells[3].Value = UserControl5.DxfTab.Rows[i][3]; dgvPolyLine.Rows[i].Cells[4].Value = UserControl5.DxfTab.Rows[i][4]; dgvPolyLine.Rows[i].Cells[5].Value = UserControl5.DxfTab.Rows[i][5]; MessageBox.Show(dgvPolyLine.Rows[i].Cells[0].Value.ToString()); } message打印有数据,但是页面未显示
qq_30803751 2016-08-27
  • 打赏
  • 举报
回复
我就奇怪了,明明有数据显示不了
sun_cathay 2016-08-27
  • 打赏
  • 举报
回复
代码看不出问题

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧