我使用LINQ填充我的DataGridView,我希望有自定义标题(包括空格)。
这就是我的DataGridView标题应该是这样的:
Private db As New Data.Linq.DataContext("Data Source=SQL01;Initial Catalog=Test;Integrated Security=True")
Private Articles As Table(Of Article) = db.GetTable(Of Article)()
Private Manufacturers As Table(Of Manufacturer) = db.GetTable(Of Manufacturer)()
Private Providers As Table(Of Provider) = db.GetTable(Of Provider)()
Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
Dim allArticles = _
From a In Articles
Join m In Manufacturers
On a.FK_Manufacturer Equals (m.PK_Manufacturer)
Join p In Providers
On a.FK_Provider Equals (p.PK_Provider)
Select Article = a.ArtNum, Description = a.Description, Pièce = a.PartNum, _
Manufacturier = m.Name, Coût = a.Cost, Fournisseur = p.Name, _
a.FlagMech, a.FlagStandard, a.FlagAvaible, a.Notes, a.CodeRSPL
DataGridView1.DataSource = allArticles
End Sub
当前结果
我一直试图只使用 Article 或Pièce这样的单词来代替#Article 或 #depièce。
我尝试了以下操作:
Select [# Article] = article.ArtNum, ... 'Error; Identifier expected
Or
Select ["# Article"] = article.ArtNum, ... 'Error; Identifier expected
Or
Select "# Article" = article.ArtNum, ... 'Error; Range variable name can be inferred only from a simple or qualified name with no arguements
我正在尝试使用LINQ吗?
答案 0 :(得分:2)
以下是我修复它的方法。我不明白选择是如何工作的。
以下内容将名为Article
的变量设置为等于a.ArtNum
Select Article = a.ArtNum
以下是我设置DataGridView自定义标头的方法:
DataGridView1.DataSource = allArticles
DataGridView1.Columns("PK").Visible = False
DataGridView1.Columns("ArtNum").HeaderText = "# article"
DataGridView1.Columns("PartNum").HeaderText = "# de pièce"
DataGridView1.Columns("Cost").HeaderText = "Coût ($)"
DataGridView1.Columns("CodeRSPL").HeaderText = "Code RSPL"