如何使用LINQ设置自定义DataGridView标题(带空格)? [英] How to Set Custom DataGridView Headers (with spaces) using LINQ?
问题描述
我正在使用LINQ填充我的DataGridView,并且想要自定义标题(其中将包含空格)。
通缉结果
这就是我的DataGridView标头应该看起来像:
构建我的DataGridView
私有数据库作为新的Data.Linq.DataContext(数据源= SQL01;初始目录=测试;集成安全= True)
私人文章作为表(文章)= db.GetTable(文章)()
私有制造商作为表(制造商)= db.GetTable(制造商)()
私人提供者作为表(供应商)= db.GetTable(供应商)()
Private Sub btnLoad_Click(sender As System.Object,e As System.EventArgs)处理btnLoad.Click
Dim allArticles = _
从In文章
在制造商中加入m
在a上.FK_Manufacturer Equals(m.PK_Manufacturer)
加入p提供者
在a.FK_Provider Equals(p.PK_Provider)
选择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。
我尝试了以下操作:
选择[#Article] = article。 ArtNum,...'错误;标识符预期
或
选择[#Article] = article.ArtNum,...'错误;标识符预期
或
选择#Article= article.ArtNum,...'错误;范围变量名只能从简单的或没有争论的名字中推断出来
尝试甚至可能使用LINQ?
以下是我如何修复它。我不理解选择如何工作。
以下将设置一个名为 Article
的变量等于 a.ArtNum
$ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ p>
如何设置自定义标题文本
以下是我如何设置我的DataGridView自定义标题:
$ $ p $ DataGridView1.DataSource = allArticles
DataGridView1.Columns(PK)。Visible = False
DataGridView1.Columns(ArtNum)。HeaderText =#article
DataGridView1.Columns(PartNum)。HeaderText =#depièce
DataGridView1.Columns(Cost ).HeaderText =Coût($)
DataGridView1.Columns(CodeRSPL)。HeaderText =Code RSPL
I am populating my DataGridView using LINQ and I would like to have custom headers (which will include spaces).
Wanted Result
This is what my DataGridView headers should look like:
Building My 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
Current Result
I'm stuck trying to make my headers with only 1 word such as Article or Pièce instead of # Article or # de pièce.
I tried doing the following:
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
Is what I'm trying even possible using LINQ?
Here's how I fixed it. I wasn't understanding how the select worked.
The following will set a variable named Article
to equal a.ArtNum
Select Article = a.ArtNum
How To Set Custom Header Text
Here is how I set my DataGridView custom headers:
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"
这篇关于如何使用LINQ设置自定义DataGridView标题(带空格)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!