开发者

C# datagridview Wrong column index

开发者 https://www.devze.com 2023-02-09 22:17 出处:网络
i\'ve got an event handler for columncontentc开发者_JAVA百科licked and it works fine, until i shorten the datalist with stored procedure. after that the indexnum that is return is 0 instead of 5 or 6.

i've got an event handler for columncontentc开发者_JAVA百科licked and it works fine, until i shorten the datalist with stored procedure. after that the indexnum that is return is 0 instead of 5 or 6. Do i have to refresh datagridview or something?

here's te code

:

int lastcol = dataGridView1.Columns.Count;
       // MessageBox.Show(e.ColumnIndex.ToString() + lastcol.ToString());
        if (e.ColumnIndex == lastcol - 1)
        {
            int index = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());


            Global.size = this.Size;
            Global.position = this.Location;
            Global.overzicht_select = index.ToString();


            if (Global.give_return == false)
            {

                switch(type)
                {

                    case 1:
                    Global.edit_form_proj = false;
                    project_form project_form1 = new project_form(this);
                    project_form1.Show(this);
                    this.Hide();
                    break;



                    case 2:
                    Global.edit_form_bedr = false;
                    bedrijf_form bedrijf_form1 = new bedrijf_form(this);
                    bedrijf_form1.Show(this);
                    this.Hide();
                    break;


                    case 3:
                    Global.edit_form_pers = false;
                    persoon_form persoon_form1 = new persoon_form(this);
                    persoon_form1.Show(this);
                    this.Hide();
                    break;
                }
            }
            else
            {
                Global.return_id = index.ToString();
                if (pf != null)
                {
                    pf.fill_id();
                }
                if (pr != null)
                {
                    pr.fill_id();
                }
                Global.give_return = false;
                Close();
            }
        }
    }

}


I found my problem. the column that I wanted clickable is a buttoncolumn, witch I add when loading the grid. but after filter that column doesnt get refresh or get new data so it things i is the first and only column left whilst the other columns get rebuilt. so calling dataGridView1.Columns.Clear(); and recreating the button column after grid is refilld did the trick, –

0

精彩评论

暂无评论...
验证码 换一张
取 消