473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Datagrid customization for custom objects

Hello,

I wrote a custom object that Inherits from CollectionBase.
This would, my object fits in a datagrid.

However, my object (_obj) contains data and references I do NOT want the
datagrid to display.

I tried doing this :

Dim dtgStyle As New DataGridTableStyle
dtgStyle.MappingName = "Parts"

Dim colId As New DataGridTextBoxColumn
Dim colName As New DataGridTextBoxColumn
<...>

With colId
.MappingName = "id"
.HeaderText = "ID"
.TextBox.Enabled = False
End With

With colName
.MappingName = "name"
.HeaderText = "Nom"
End With

With colNotes
.MappingName = "notes"
.Width = 0
End With

<...>

With dtgStyle.GridColumnStyles
.Add(colId)
.Add(colName)
.Add(colSerieSize)
.Add(colEnabled)
.Add(colTrained)

' hidden
.Add(colNotes)
.Add(colWeight)
End With

With dtgParts

.TableStyles.Clear()
.TableStyles.Add(dtgStyle)
.DataSource = _obj
End With


This does not seem to help. DO you know how I can acheive this ?

Regards,
Will
Nov 21 '05 #1
1 1055
Hello folks,

Just coming back here because I really don't get it.
I copied below the code I run to figure out how to get it working.

The style does not work because the column width does not change. Also,
width=0 does not work either so I cannot hide a column.

What is wrong ?
Here is my main:

Module modMain

Public Sub main()
Dim stuffs As New clsStuffs

stuffs.add(New clsStuff("aa"))
stuffs.add(New clsStuff("bb"))
stuffs.add(New clsStuff("cccc"))
stuffs.add(New clsStuff("dddd"))

Dim dlg As New Form1
Dim dtgStyle As New DataGridTableStyle
dtgStyle.MappingName = "whatdoIputhere"

Dim colName As New DataGridTextBoxColumn
Dim colID As New DataGridTextBoxColumn
Dim colEnabled As New DataGridBoolColumn

With colName
.MappingName = "name"

.Width = 300
.HeaderText = "pouet"
End With

With colEnabled
.MappingName = "enabled"
.Width = 100
End With

With colID
.MappingName = "id"
.Width = 0
End With

dtgStyle.GridColumnStyles.Clear()
dtgStyle.GridColumnStyles.Add(colName)
dtgStyle.GridColumnStyles.Add(colEnabled)
dtgStyle.GridColumnStyles.Add(colID)
With dlg

.DataGrid1.TableStyles.Clear()
.DataGrid1.TableStyles.Add(dtgStyle)
.DataGrid1.DataSource = stuffs

.ShowDialog()
End With

End Sub
End Module

Here is the clsStuffs class :
Imports System.ComponentModel

Public Class clsStuffs
Inherits CollectionBase
Public Function add(ByVal stuff As clsStuff) As Integer
Return (list.Add(stuff))
End Function
End Class


and finally :
Imports System.ComponentModel

Public Class clsStuff

Private Shared _count As Integer
Private _id As Integer
Private _name As String
Private _enaabled As Boolean

Public Property name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property

'<Browsable(False)> _
Public ReadOnly Property id() As Integer
Get
Return _id
End Get
End Property

Public Sub New(ByVal name As String)
_name = name
_id = _count
_count += 1

End Sub

Public Property enabled() As Boolean
Get
Return _enaabled
End Get
Set(ByVal Value As Boolean)
_enaabled = Value
End Set
End Property

End Class

to get it working you also need a form called form1 containing a
datagrid called datagrid1.
ANy help appreciated.
Will
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PatLaf | last post by:
I would like to be able to build a datagrid that has two buttons in each cell similar to the functionality provided by the winforms numericupdown control. I have an app that will require the user to...
2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
1
by: Arcadius A. | last post by:
Hello! I'm trying to bind an array of custom objects to a ASP.NET DataGrid: private void Page_Load(object sender, System.EventArgs e) { DataGrid1= new DataGrid();...
0
by: berg | last post by:
All, I am binding an ArrayList full of custom objects to an DataGrid. The property in the custom class are all public. I define a DataGridTableStyle and set the MappingName to "ArrayList". I...
1
by: Conawapa11 | last post by:
I'm having trouble figuring this problem out and every example out there deals with simple objects within a custom collection. Take this example: public class ComplexClass { private int id;...
3
by: Just D | last post by:
Hi, If anybody needs to show some data retrieved from the database table, what method is more preferrable? 1. DataSet ds = ...; DataGrid.Data.Source.ds; DataGrid.Bind(); 2. Write a custom...
2
by: MichaelY | last post by:
Ok...I'm gonna regret this...but here goes....(promise I'm not trolling) After several years of using the provided ASP.NET data display controls (DataGrids, Repeaters, and now the GridView amoung...
2
by: Simone | last post by:
Hi, i have an application created with Vb.Net 2002 and .Net Framework 1.1; in a Main Form I have a Datagrid populated with a Datawiew. When i populate a Datagrid i receive a Big red X into...
3
by: Tom S. | last post by:
VS.Net 2003 V 7.1.3088 ..Net Framework V 1.1.4322 SP1 WinXP SP2 I have a WinForms project that I'm having trouble with. I have a custom user control ( all code based, no visual ) and another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.