由文本框输入设置的Gridview列标题?

时间:2012-04-10 17:50:35

标签: c#

所以我在Windows窗体应用程序中有一个gridview,当我单击我的按钮时,gridview被填充,标题列/行读取Tag(因为我设置它(在代码下面))但是如果我想要标签怎么办?标题将替换为文本框中输入的内容,如何更改以下代码?

Tag = n.Element("GroupName").Value

完整代码:

        XDocument xDoc = XDocument.Load(tagUri);
        var Tag = xDoc.Descendants("Group")
            .Select(n => new
            {

                Tag = n.Element("GroupName").Value, // Tag in this line represents the column name, I would like this changed to be a textbox input. 
            })
            .ToList();

        dataGridView4.DataSource = Tag;

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以在之后设置列标题:

datagridView4.Columns[0].HeaderText = textbox1.Text;
相关问题