Please Help im going Crazy on this one

  • Thread starter Thread starter Newbie!
  • Start date Start date
N

Newbie!

Hi Group,

Im trying to Format some coloums on my Datagrid so that only 3 Coloums are
show out of the 20 in my Dataset, I just carn`t for the life of me get it to
work, i`ve looked everywhere for info but with no joy. Does anybody have any
example code links? or even better project links? here is my following Code
if anybody can help me with this please

Many thanks
Si

Private Sub frmContracts_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If odcContracts.State <> ConnectionState.Open Then odcContracts.Open()
odaContracts.Fill(dsContracts)
Dim aGridTableStyle As New DataGridTableStyle()
aGridTableStyle.MappingName = "mapcontracts"
Dim aCol1 As New DataGridTextBoxColumn()
Dim aCol2 As New DataGridTextBoxColumn()
Dim aCol3 As New DataGridTextBoxColumn()
With aCol1
.MappingName = "ID"
.Width = 0
End With
With aCol2
.MappingName = "Contact"
.HeaderText = "Contact"
.Width = 65
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol3
.. MappingName = "Company"
.HeaderText = "Company"
.Width = 50
.Alignment = HorizontalAlignment.Center
.NullText = ""
.TextBox.Enabled = True
End With
With aGridTableStyle.GridColumnStyles
.Add(aCol1)
.Add(aCol2)
.Add(aCol3)
End With
dgdContracts.TableStyles.Add(aGridTableStyle)
If dsContracts.Tables(0).Rows.Count > 0 Then
With dgdContracts
.DataSource = dsContracts.Tables(0)
.Expand(-1)
.NavigateTo(0, "Contracts")
End With
End If
End Sub
 
Hi Newbie,

I do not see direct errors.

Maybe I oversee it also, but some things I cannot see.
The membernames, are they in the right cases?

What I see in the code but that has nothing to do with the problem is this
If odcContracts.State <> ConnectionState.Open Then odcContracts.Open()

The dataAdapter opens himself a connection when it is not open, so that one
is not necessary.
odaContracts.Fill(dsContracts)

I hope this helps a very little bit?

Cor
 
Hi,

Before you add the tablestyle to the grid you need to set its
mapping name.

With aGridTableStyle.GridColumnStyles
.Add(aCol1)
.Add(aCol2)
.Add(aCol3)
.MappingName = dsContracts.Tables(0).TableName
End With


Ken
 
Thanks for your reply,
When i add:

..MappingName = dsContracts.Tables(0).TableName

I get an error saying D:\Excellence.NET\Contracts.vb(462): 'MappingName' is
not a member of 'System.Windows.Forms.GridColumnStylesCollection'.

I guess i need to add something else but i don`t know what

Thanks again for you help so far,

Ta
Si
 
I`ve sorted it it needed aGridTableStyle.MappingName

Judt gotta get the colour working now:(

Cheers For all you help
Ta
Si
 
better than col.width = 0

table.Columns(xxxx).ColumnMapping = MappingType.Hidden


Dominique
 
Back
Top