重命名Datagirdview列标题(映射) [英] Renaming Datagirdview column headers ( Mapping)

查看:93
本文介绍了重命名Datagirdview列标题(映射)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试重命名数据网格的列标题,该数据网格是从我从数据库获取的数据集中进行的。

问题是我需要创建映射到地图列标题的新名称与从数据库中提取的名称不同。



以下是我的代码,它不起作用...错误:TableStyles不能得到解决。



Hello, i am trying to rename the column header of a datagrid that is being pupulated from a dataset that i got from my Database.
The problem is that i need to create a mapping to map new names to the columns headers different from the ones extracted from the database.

The following is my code and its not working ... error:TableStyles cannot be resolved.

 DataGridTableStyle myGridStyle =
                    new DataGridTableStyle ();
                    myGridStyle.MappingName = "Users";

DataGridColumnStyle colStyle1 =
                    new DataGridBoolColumn ();
                    colStyle2.MappingName = "Salary";
                    DataGridColumnStyle colStyle2 =
                    new DataGridBoolColumn ();
                    colStyle2.MappingName = "Position";

                    // Add column styles to table style.
                    myGridStyle.GridColumnStyles.Add (colStyle1);
                    myGridStyle.GridColumnStyles.Add (colStyle2);

dgvResults.TableStyles.Add (myGridStyle);

推荐答案

试试以下



只需将您的DataTable分配给datagridview,然后更改列标题的名称。



Try following

Just assign your DataTable to datagridview, and change the name of the column header.

dataGridView1.DataSource=dataSet1.Tables[0];
dataGridView1.Columns[0].HeaderText="My Custom Header";







HTH




HTH

Jinal的回答是正确的。但更简单的方法是在Visual Studio中重命名列。



步骤:

1.选择要修改的Datagriview。 br $>
2.单击DataGridView任务小按钮,然后单击编辑列链接

3.在编辑列对话框中,选择要重命名的列,然后更改HeaderText到你想要的名字。

4.点击确定你就完成了!
Jinal's answer is correct. But an easier way is to rename the columns in Visual Studio.

Steps:
1. Select the Datagriview you want to modify.
2. Click the DataGridView tasks small button, and click the Edit Columns link
3. On the Edit Columns dialog, select the column you wish to rename, and change the HeaderText to your desired name.
4. Click OK and you're done!


in free pascal



in free pascal

DBGrid1.Columns[0].Title.Caption   :='الاسم التجارى';
   DBGrid1.Columns[1].Title.Caption   :='الاسم العلمى';
    DBGrid1.Columns[2].Title.Caption   :='السعر';
     DBGrid1.Columns[3].Title.Caption   :='ملاحظات';


这篇关于重命名Datagirdview列标题(映射)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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