连接数据网格视图列到数据库时出错 [英] error with connect datagrid view column to data base

查看:70
本文介绍了连接数据网格视图列到数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一列数据gridview与类型组合框连接到数据库,并将其更改为第二列的数据源,使用类型组合框更改我的代码是正确的并且工作但更改第一列并查看secondd列中的数据看到这个错误我该如何解决这个问题???



datagridview中出现以下异常

system.argumentexception: datagridviewcomboboxcell值无效

替换此默认对话框请处理数据错误事件



请帮帮我....... ..

  private   void  foroosh_Load(  object  sender,EventArgs e)
{
DataTable p = new System.Data .DataTable();
p = selectcolor( type );
(dataGridView2.Columns [ 0 ] as DataGridViewComboBoxColumn).DataSource = p;
(dataGridView2.Columns [ 0 ] as DataGridViewComboBoxColumn).DisplayMember = type;
DataTable pc = new System.Data.DataTable();
pc = sel();
(dataGridView2.Columns [ 4 ] as DataGridViewComboBoxColumn).DataSource = pc;
(dataGridView2.Columns [ 4 ] as DataGridViewComboBoxColumn).DisplayMember = color;
}




私人 void dataGridView2_CellEnter( object sender,DataGridViewCellEventArgs e)
{

DataTable pe = new System.Data.DataTable();
string pi;
int f;
if (e.ColumnIndex == 2
{
pe = selectcolor( tip 其中type =' + dataGridView2.Rows [ 0 ]。单元格[ 0 ]。Value.ToString()+ ');
(dataGridView2.Columns [ 2 ] as DataGridViewComboBoxColumn).DataSource = pe;
(dataGridView2.Columns [ 2 ] as DataGridViewComboBoxColumn).DisplayMember = tip;
}
else if (e.ColumnIndex == 1
{
pi = varab(dataGridView2.Rows [e.RowIndex] .Cells [ 0 ] .Value.ToString());
if (pi == ميلادي
{
for (f = 1950 ; f < span class =code-keyword>< = 2020 ; f ++)
(dataGridView2.Columns [ 1 ] as DataGridViewComboBoxColumn).Items.Add(f);
}
else
{
for (f = 1300 ; f < = 1400 ; f ++)
(dataGridView2.Columns [ 1 ] as DataGridViewComboBoxColumn).Items.Add( F);
}
}


}

解决方案

http://social.msdn.microsoft.com/Forums/ en-US / Vsexpressvb / thread / 33a87afd-6e7d-428a-b439-76eec83f137a / [ ^ ] ..

就您的问题进行了几次讨论..

i want to connect a column of data gridview with type combo box to a data base and with change value of this the data source of second column with type combo box change my code is correct and work but with change first column and see data in secondd column see this error how can i solve this???

the following exception occured in the datagridview
system.argumentexception:datagridviewcomboboxcell value is not valid
to replace this default dialog please handle the data error event

please help me.........

private void foroosh_Load(object sender, EventArgs e)
        {
            DataTable p = new System.Data.DataTable();
            p = selectcolor("type","");
         (dataGridView2.Columns[0] as DataGridViewComboBoxColumn).DataSource = p;
         (dataGridView2.Columns[0] as DataGridViewComboBoxColumn).DisplayMember = "type";
         DataTable pc = new System.Data.DataTable();
            pc = sel();
         (dataGridView2.Columns[4] as DataGridViewComboBoxColumn).DataSource = pc;
         (dataGridView2.Columns[4] as DataGridViewComboBoxColumn).DisplayMember = "color";
}




 private void dataGridView2_CellEnter(object sender, DataGridViewCellEventArgs e)
        {

            DataTable pe = new System.Data.DataTable();
            string pi;
            int f;
            if (e.ColumnIndex == 2)
            {
                pe = selectcolor("tip", "where type= '" + dataGridView2.Rows[0].Cells[0].Value.ToString() + "'");
                (dataGridView2.Columns[2] as DataGridViewComboBoxColumn).DataSource = pe;
                (dataGridView2.Columns[2] as DataGridViewComboBoxColumn).DisplayMember = "tip";
            }
            else if(e.ColumnIndex == 1)
            {
                pi = varab(dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString());
                if (pi == "ميلادي")
                {
                    for (f = 1950; f <= 2020; f++)
                        (dataGridView2.Columns[1] as DataGridViewComboBoxColumn).Items.Add(f);
                }
                else
                {
                    for (f = 1300; f <= 1400; f++)
                        (dataGridView2.Columns[1] as DataGridViewComboBoxColumn).Items.Add(f);
                }
            }


            }

解决方案

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/33a87afd-6e7d-428a-b439-76eec83f137a/[^]..
Several discussions are given regarding your issue..


这篇关于连接数据网格视图列到数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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