请给我一个c#形式的解决方案: [英] Please ,Give me the solution in c# form:

查看:108
本文介绍了请给我一个c#形式的解决方案:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它显示以下错误: - < br style ="color:#111111; font-family:'Segoe UI',Arial,sans-serif; font-size:14px">


System.InvalidCastException:'无法将'System.Windows.Forms.DataGridViewTextBoxColumn'类型的对象强制转换为'System.Windows.Forms.DataGridViewImageColumn'。'

 我的代码是:

 My code is:

  private void Form2_Load(object sender, EventArgs e)
        {
            con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Admin\source\repos\DATABASE\data2.sql.mdf;Integrated Security=True;Connect Timeout=30");
            con.Open();
            adpt = new SqlDataAdapter("Select * from Details ", con);
            dt = new DataTable();
            adpt.Fill(dt);
            dataGridView.DataSource = dt;
            
        
            DataGridViewImageColumn imgcol = new DataGridViewImageColumn();
            imgcol=(DataGridViewImageColumn)dataGridView.Columns[14];
            imgcol.ImageLayout = DataGridViewImageCellLayout.Stretch;


            adpt.Dispose();




推荐答案

嗨!

dataGridView.Columns [14]是
DataGridViewTextBoxColumn,你试着将它转换为
DataGridViewImageColumn。

dataGridView.Columns[14] is a DataGridViewTextBoxColumn and your'e try to cast it to the DataGridViewImageColumn.

也许,你忘记添加
DataGridViewImageColumn
到dataGridView?

Maybe, you forgot to add DataGridViewImageColumn to the dataGridView?


这篇关于请给我一个c#形式的解决方案:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆