Re: Format Datagrid
From: One Handed Man \( OHM - Terry Burns \) ("One)
Date: 08/11/04
- Next message: Ricky W. Hunt: "Re: Assigning one object to another"
- Previous message: Your_name: "Re: For vs. For Each"
- In reply to: Dave Edwards: "Re: Format Datagrid"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 11 Aug 2004 16:12:45 +0100
OR something like
Friend WithEvents DataGridTextBoxColumn1 As
System.Windows.Forms.DataGridTextBoxColumn
Me.DataGridTextBoxColumn1 = New System.Windows.Forms.DataGridTextBoxColumn
Me.DataGrid2.TableStyles.AddRange(New
System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1})
Me.DataGridTextBoxColumn1.Width = 75
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me
Time flies when you don't know what you're doing
"Dave Edwards" <none@none.com> wrote in message
news:_rrSc.1660$7E3.1306@newsfe5-gui.ntli.net...
> Thanks for this, I'll work my way through it and see if i can get it to
> work, I don't know if its just me but i find it surprising that its so
> complicated and tricky to adjust a column width in a datagrid.
>
> "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message
> news:OnUkOJ7fEHA.2020@TK2MSFTNGP10.phx.gbl...
> > Try this. Without adding the DataGridColumnColumnStyle ( Which must be
> > Inherited ) you have no styles to reference. Look up the documentation
for
> > more information.
> >
> > HTH
> >
> > Class MyColumnStyle
> > Inherits DataGridColumnStyle
> >
> >
> > Protected Overrides Sub Abort(ByVal rowNum As Integer)
> >
> > End Sub
> >
> > Protected Overrides Function Commit(ByVal dataSource As
> > System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As
Boolean
> >
> > End Function
> >
> > Protected Overloads Overrides Sub Edit(ByVal source As
> > System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
> > bounds
> > As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal
> > instantText
> > As String, ByVal cellIsVisible As Boolean)
> >
> > End Sub
> >
> > Protected Overrides Function GetMinimumHeight() As Integer
> >
> > End Function
> >
> > Protected Overrides Function GetPreferredHeight(ByVal g As
> > System.Drawing.Graphics, ByVal value As Object) As Integer
> >
> > End Function
> >
> > Protected Overrides Function GetPreferredSize(ByVal g As
> > System.Drawing.Graphics, ByVal value As Object) As System.Drawing.Size
> >
> > End Function
> >
> > Protected Overloads Overrides Sub Paint(ByVal g As
> > System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal
> > source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer)
> >
> > End Sub
> >
> > Protected Overloads Overrides Sub Paint(ByVal g As
> > System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal
> > source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer,
> > ByVal alignToRight As Boolean)
> >
> > End Sub
> > End Class
> >
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > Dim Style2 As New DataGridTableStyle
> >
> > Try
> > Style2.GridColumnStyles.Add(New MyColumnStyle)
> > Style2.GridColumnStyles.Add(New MyColumnStyle)
> >
> > DataGrid2.TableStyles.Add(Style2)
> > DataGrid2.TableStyles(0).GridColumnStyles.Item(0).Width = 120
> > DataGrid2.TableStyles(0).GridColumnStyles.Item(1).Width = 400
> > Catch ex As Exception
> >
> > MessageBox.Show(ex.Message)
> > End Try
> > End Sub
> >
> > --
> >
> > OHM ( Terry Burns )
> > . . . One-Handed-Man . . .
> > If U Need My Email ,Ask Me
> >
> > Time flies when you don't know what you're doing
> >
> > "Dave Edwards" <none@none.com> wrote in message
> > news:qCqSc.1640$7E3.353@newsfe5-gui.ntli.net...
> >> Thanks for this, I see what your saying but I think i'm being
> >> particularly
> >> thick today as I can't work out what i should be doing with the code
you
> >> supplied,
> >> thanks again
> >> Dave
> >>
> >> "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
> > message
> >> news:ORduUo6fEHA.592@TK2MSFTNGP11.phx.gbl...
> >> > You have not added any column styles, so you are trying to reference
a
> >> > style
> >> > which does not exist
> >> >
> >> > Style2.GridColumnStyles.Add(
> >> >
> >> > HTH
> >> > --
> >> >
> >> > OHM ( Terry Burns )
> >> > . . . One-Handed-Man . . .
> >> > If U Need My Email ,Ask Me
> >> >
> >> > Time flies when you don't know what you're doing
> >> >
> >> > "Dave Edwards" <none@none.com> wrote in message
> >> > news:SzpSc.1373$7E3.773@newsfe5-gui.ntli.net...
> >> >> Hi Folks,
> >> >> Can someone help me out with this code, all i'm trying to do is
format
> > my
> >> >> datagrid so that I have the first col of 120 and the second of 400,
> >> >> but
> > i
> >> >> keep getting
> >> >>
> >> >> "An unhandled exception of type 'System.ArgumentOutOfRangeException'
> >> >> occurred in mscorlib.dll
> >> >> Aditional information: Index was out of range. Must be non-negative
> > and
> >> >> less than the size of the collection. " at the * line of code.
> >> >>
> >> >> Private Sub GenEventLog()
> >> >>
> >> >> If File.Exists("events.xml") Then
> >> >> dsEvents.ReadXml("events.xml")
> >> >> DataGrid2.DataSource = dsEvents.Tables(0)
> >> >> Else
> >> >>
> >> >> Dim myXmlTextWriter As XmlTextWriter = New
XmlTextWriter("events.xml",
> >> >> System.Text.Encoding.Unicode)
> >> >> myXmlTextWriter.Formatting = System.Xml.Formatting.Indented
> >> >> myXmlTextWriter.WriteStartElement("events")
> >> >> myXmlTextWriter.WriteStartElement("event")
> >> >> myXmlTextWriter.WriteElementString("Datetime", Now())
> >> >> myXmlTextWriter.WriteElementString("Action", "Event log created")
> >> >> myXmlTextWriter.WriteEndElement()
> >> >> myXmlTextWriter.WriteEndElement()
> >> >> myXmlTextWriter.Flush()
> >> >> myXmlTextWriter.Close()
> >> >> dsEvents.ReadXml("events.xml")
> >> >> DataGrid2.DataSource = dsEvents.Tables(0)
> >> >> End If
> >> >>
> >> >> Dim Style2 As New DataGridTableStyle
> >> >> Style2.MappingName = dsEvents.GetType().Name
> >> >> DataGrid2.TableStyles.Add(Style2)
> >> >> *DataGrid2.TableStyles(0).GridColumnStyles.Item(0).Width = 120* <
> >> >> error
> >> >> here.
> >> >> DataGrid2.TableStyles(0).GridColumnStyles.Item(1).Width = 400
> >> >>
> >> >> End Sub
> >> >>
> >> >> Any help Very much appreciated.
> >> >> Thanks
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>
- Next message: Ricky W. Hunt: "Re: Assigning one object to another"
- Previous message: Your_name: "Re: For vs. For Each"
- In reply to: Dave Edwards: "Re: Format Datagrid"
- Messages sorted by: [ date ] [ thread ]