Re: Format Datagrid

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: One Handed Man \( OHM - Terry Burns \) ("One)
Date: 08/11/04


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
> >>
> >>
> >
> >
>
>


Relevant Pages

  • Re: stupid question...waiting for a stupid answer
    ... private void notifyChanges{ ... Unless you believe that a boolean can be passed by reference, ... void called(int x, Holder y, Holder z) ...
    (comp.lang.java.programmer)
  • Re: How to create the project referencing library, which user may not have on his computer?
    ... As in the "Air Code" Nobody posted you have a boolean set to true if ... force user to install that library prior to the installation of my app). ... How to code that reference conditionally? ... Public Sub Main ...
    (microsoft.public.vb.general.discussion)
  • Re: stupid question...waiting for a stupid answer
    ... private void notifyChanges{ ... Unless you believe that a boolean can be passed by reference, ... void called(int x, Holder y, Holder z) ...
    (comp.lang.java.programmer)
  • Re: Referencing Boolean Variable using a for loop
    ... I suggest you use an array of Boolean values, or, if you want to keep alpha references, a collection. ... and check the said reference) to use the Scripting library. ... Public Sub ArrayOrCollection() ... Dim bbb As New Scripting.Dictionary ...
    (microsoft.public.access.modulesdaovba)
  • RE: Uppercase
    ... instantText As String, ByVal cellIsVisible As Boolean) ... ByVal rowNum As Integer) As Object ... Incoming mail is certified Virus Free. ... Checked by AVG Anti-Virus. ...
    (microsoft.public.dotnet.languages.vb)