Re: Format Datagrid
From: One Handed Man \( OHM - Terry Burns \) ("One)
Date: 08/11/04
- Next message: Just Me: "Using Regular Expressions with a RichTextBox"
- Previous message: StepHenHairNet: "Copy Method on "Hidden" OWC Spreadsheets"
- In reply to: Dave Edwards: "Re: Format Datagrid"
- Next in thread: Dave Edwards: "Re: Format Datagrid"
- Reply: Dave Edwards: "Re: Format Datagrid"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 11 Aug 2004 15:48:45 +0100
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: Just Me: "Using Regular Expressions with a RichTextBox"
- Previous message: StepHenHairNet: "Copy Method on "Hidden" OWC Spreadsheets"
- In reply to: Dave Edwards: "Re: Format Datagrid"
- Next in thread: Dave Edwards: "Re: Format Datagrid"
- Reply: Dave Edwards: "Re: Format Datagrid"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|