Note: While this sample is in VB.NET, I am language agnostic when it comes to a solution (i.e. I'll either code in back up in C# or convert a C# solution)
Setup:
1. Class with three properties, Firstname, Lastname, Age
2. Create 5 instances and add then to a List(of Class)
3. Set the List as the datasource for a DataGridView(setup as read only)
4. By default, the datagridview displays three columns and five rows
Question, is there a way to mark (via an attribute for example) the Age property in TestClass so it does not automatically bind/display in the grid?
Dim foo As New List(Of TestClass)
For i As Integer = 1 To 5
foo.Add(New TestClass("FirstTest " & i.ToString(), "LastTest " & i.ToString(), i))
Next
Me.DataGridView1.DataSource = foo
I thought I could do it by marking the age property as
<System.ComponentModel.Bindable(False)> _
Public Property Age() As Integer
Get
Return _age
End Get
Set(ByVal value As Integer)
_age = value
End Set
End Property
But that didn't work, it still gets bound (at least visually)
Question
+Biscuits Brown MVC
Note: While this sample is in VB.NET, I am language agnostic when it comes to a solution (i.e. I'll either code in back up in C# or convert a C# solution)
Setup:
1. Class with three properties, Firstname, Lastname, Age
2. Create 5 instances and add then to a List(of Class)
3. Set the List as the datasource for a DataGridView(setup as read only)
4. By default, the datagridview displays three columns and five rows
Question, is there a way to mark (via an attribute for example) the Age property in TestClass so it does not automatically bind/display in the grid?
Dim foo As New List(Of TestClass) For i As Integer = 1 To 5 foo.Add(New TestClass("FirstTest " & i.ToString(), "LastTest " & i.ToString(), i)) Next Me.DataGridView1.DataSource = fooI thought I could do it by marking the age property as
But that didn't work, it still gets bound (at least visually)
Link to comment
Share on other sites
6 answers to this question
Recommended Posts