本文介绍了如何在动态更改列的宽度后保存数据网格视图中列的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在datagridview中保存列的宽度。我已经编写了这段代码,但是没有得到正确的输出。



当我们关闭表单时,datagridview列的宽度将被保存。



每当我们反复调试时,它会在datagridview中显示列宽为已保存列宽







我应该在哪里写这些代码。



I want to save width of a column in a datagridview. I have written this code but I didn't get the correct output.

when we close a form the datagridview columns width will be saved.

Whenever we debug again and again it will show that column width as Saved column width

in the datagridview.

For that where should I write these code.

DataTable dt = new DataTable(DG.Name);
            dt.Columns.Add("name");
            dt.Columns.Add("width");
            dt.Columns.Add("index");
            for (int i = 0; i < DG.Columns.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["name"] = DG.Columns[i].Name;
                dr["width"] = DG.Columns[i].Width;
                dr["index"] = DG.Columns[i].DisplayIndex;
                string name = "";
                int width, index;
                name = dr["name"].ToString();
                width = Convert.ToInt32(dr["width"].ToString());
                index = Convert.ToInt32(dr["width"].ToString());
                Details_Grid.Columns[i].Width = width;
            }

请您建议我正确的代码

推荐答案


这篇关于如何在动态更改列的宽度后保存数据网格视图中列的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 07:02