Vb.net 从表值创建DataGridView列
我正在使用Windows窗体独立应用程序中的数据网格视图在VB.NET中将项目显示为excel电子表格。我得到了一个名为CostTypes的表,其列名为[CostTypeID,CostType],值为[1,外部]和[2,内部](这些是常量,但可以向表中添加更多值) 我想在DataGridView中创建名为[External,Internal]的列。如果我直接使用databiding,我会得到[CostTypeID,CostType]列,这不是我想要的 如果有人能解释如何在运行时在datagridview中创建列,或者如何使用LINQ从数据库中检索数据,从而使[External,Internal]成为列,那就太好了Vb.net 从表值创建DataGridView列,vb.net,Vb.net,我正在使用Windows窗体独立应用程序中的数据网格视图在VB.NET中将项目显示为excel电子表格。我得到了一个名为CostTypes的表,其列名为[CostTypeID,CostType],值为[1,外部]和[2,内部](这些是常量,但可以向表中添加更多值) 我想在DataGridView中创建名为[External,Internal]的列。如果我直接使用databiding,我会得到[CostTypeID,CostType]列,这不是我想要的 如果有人能解释如何在运行时在datagrid
提前感谢。您可以使用列表视图在一行中显示项目 像这样的
<asp:ListView ID="NewsLV" runat="server">
<ItemTemplate>
<td id="Td1" runat="server" valign="top" style="width: 33%;">
<asp:Label ID="titleLabel" runat="server" Text='<%# Eval("CostType") %>' CssClass="GridTitle" />
<br />
<div style="padding: 2px;">
<asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("CostTypeID") %>'
Font-Size="X-Small" />
</div>
</td>
</ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server" border="0" style="">
<tr id="itemPlaceholderContainer" runat="server">
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
您可以使用列表视图在一行中显示项目
像这样的
<asp:ListView ID="NewsLV" runat="server">
<ItemTemplate>
<td id="Td1" runat="server" valign="top" style="width: 33%;">
<asp:Label ID="titleLabel" runat="server" Text='<%# Eval("CostType") %>' CssClass="GridTitle" />
<br />
<div style="padding: 2px;">
<asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("CostTypeID") %>'
Font-Size="X-Small" />
</div>
</td>
</ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server" border="0" style="">
<tr id="itemPlaceholderContainer" runat="server">
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
在这里找到答案
谢谢在这里找到答案
谢谢您所能做的就是创建一个Sub,它将为您创建列。当你这样做的时候,你有很多控制权。以下是一个例子:
With DataGridView1
.AutoGenerateColumns = False
Dim columnCostType As New DataGridViewTextBoxColumn
With columnCostType
.HeaderText = "Cost Type"
.DataPropertyName = CustomObject.CostType
.Name = CustomObject.CostType
End With
.Columns.Add(columnCostType)
End With
您可以做的是创建一个子节点,该子节点将为您创建列。当你这样做的时候,你有很多控制权。以下是一个例子:
With DataGridView1
.AutoGenerateColumns = False
Dim columnCostType As New DataGridViewTextBoxColumn
With columnCostType
.HeaderText = "Cost Type"
.DataPropertyName = CustomObject.CostType
.Name = CustomObject.CostType
End With
.Columns.Add(columnCostType)
End With
对不起,我应该提一下。这是一个Windows应用程序,不是web应用程序。对不起,我应该提到它。它是Windows应用程序而不是web应用程序