Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用DataSource时如何操作datagridview列?_C#_Datagrid_Datagridview_Datasource - Fatal编程技术网

C# 使用DataSource时如何操作datagridview列?

C# 使用DataSource时如何操作datagridview列?,c#,datagrid,datagridview,datasource,C#,Datagrid,Datagridview,Datasource,我在c#上使用datagridview,并向它提供一个数据源对象。如果AutoGenerateColumns为true,则一切正常,所有列都会与其内容一起生成。但我只想显示第1列,并将其余列的信息用于第1列工具提示 我尝试将AutoGenerateColumns设置为false,并创建了一个名为的列,就像在AutoGenerateColumns为true时添加的第一列一样,但这样做时没有添加行 正确的方法是什么 更新: 在我要隐藏的所有字段上方添加[Browsable(false)]:) 现在,

我在c#上使用datagridview,并向它提供一个数据源对象。如果
AutoGenerateColumns
true
,则一切正常,所有列都会与其内容一起生成。但我只想显示第1列,并将其余列的信息用于第1列工具提示

我尝试将
AutoGenerateColumns
设置为
false
,并创建了一个名为的列,就像在
AutoGenerateColumns
true
时添加的第一列一样,但这样做时没有添加行

正确的方法是什么

更新: 在我要隐藏的所有字段上方添加
[Browsable(false)]
:)


现在,我如何使用“隐藏”列中的数据并将其用于第一列单元格工具提示?

我想您需要的是这样的:

<asp:GridView ID="gridStatus" runat="server" AutoGenerateColumns="False"  DataSourceID="SqlDataSourceForStatusGrid">
    <Columns>
        <asp:BoundField DataField="ID" Visible =false />
        <asp:BoundField DataField="StudentName" HeaderText="Name" SortExpression="StudentName" />


通过这种方式,您将在其中包含列,并且可以使用Grid.Rows[selectedRow].Cells[index]。下面是来自msdn的代码片段

// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(object sender, 
    DataGridViewCellFormattingEventArgs e)
    {
    if ( (e.ColumnIndex == this.dataGridView1.Columns["Rating"].Index)
        && e.Value != null )
    {
        DataGridViewCell cell = 
            this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        if (e.Value.Equals("*"))
        {                
            cell.ToolTipText = "very bad"; // you can get the value from your other cells using the above technique with .value instead of .index
        }
        else if (e.Value.Equals("**"))
        {
            cell.ToolTipText = "bad";
        }
        else if (e.Value.Equals("***"))
        {
            cell.ToolTipText = "good";
        }
        else if (e.Value.Equals("****"))
        {
            cell.ToolTipText = "very good";
        }
    }
}

正确回答这个问题确实需要一个代码示例——您确定您正确地连接了专栏吗?您需要将列上的DataPropertyName设置为希望该列使用的属性是否使用visual studio 08/10?