Click here to Skip to main content
15,908,775 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionCrystal Report Opening Problem. Pin
Nanda_MR26-Dec-08 18:26
Nanda_MR26-Dec-08 18:26 
QuestionNeed similar Coding for Treeview Pin
bharanidharanit26-Dec-08 15:46
bharanidharanit26-Dec-08 15:46 
AnswerRe: Need similar Coding for Treeview Pin
bharanidharanit28-Dec-08 14:39
bharanidharanit28-Dec-08 14:39 
Questioncrystal report with vb6 Pin
blade0426-Dec-08 7:38
blade0426-Dec-08 7:38 
AnswerRe: crystal report with vb6 Pin
Christian Graus26-Dec-08 12:12
protectorChristian Graus26-Dec-08 12:12 
Generalhello Pin
blade0426-Dec-08 7:31
blade0426-Dec-08 7:31 
GeneralRe: hello Pin
Christian Graus26-Dec-08 12:12
protectorChristian Graus26-Dec-08 12:12 
QuestionFirst Question - Problem repainting datagridview Pin
snakeyes200226-Dec-08 5:40
snakeyes200226-Dec-08 5:40 
I generally code for using VB.NET 2.0 and Visual Studio 2008.

I have a datagrid view bound to a dataset stored in xml file. I have implemented
several custom datagridviewtextboxcell controls - one which displays a box with a
colour beside a number. Another which displays a line of varying width beside it's
value.

These cells are drawn correctly when the value is changed, however when the form is
loaded and the datagriddview filled with data, all the cells are not painted. Only
when I select the cell by clicking does the cell repaint - this has been causing all
sorts of trouble.

I have attempted several workarounds, including a timer tick event hooked to the
invalidate method of the dgv and each displayed cell individually. Any ideas;
I probably have missed something simple.

The sample below is the custom control for the color cell - it will not work right
out of the box as it requires the Autodesk AutoCAD 2008 API

Public Class AcColorCell
  Inherits DataGridViewTextBoxCell

  <DebuggerNonUserCode()> _
  Protected Overrides Sub Paint(ByVal graphics As Graphics, ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex As Integer, ByVal elementState As DataGridViewElementStates, ByVal value As Object, _
    ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As DataGridViewCellStyle, ByVal advancedBorderStyle As DataGridViewAdvancedBorderStyle, ByVal paintParts As DataGridViewPaintParts)
      'formattedValue = Nothing

      MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)

      If Me.RowIndex < 0 Then Exit Sub

      Dim ColorBoxRect As New Rectangle(cellBounds.X, cellBounds.Y, cellBounds.Width - 1, cellBounds.Height - 3)
      ColorBoxRect.Inflate(-1, -1)
      ColorBoxRect.Width = 18
      ColorBoxRect.Offset(1, 0)

      Dim TextBoxRect As New RectangleF(cellBounds.X + ColorBoxRect.Width + 4, _
                                        cellBounds.Y, cellBounds.Width - 1, cellBounds.Height - 1)

          Dim cellBackground As SolidBrush

          If Not Me.Value Is DBNull.Value Then
            If Me.Value <> 0 Then
              Dim AcColor As Autodesk.AutoCAD.Colors.Color
              Dim ColorValue As Short = CShort(Me.Value)

              AcColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, ColorValue)

              Dim r As Byte = AcColor.ColorValue.R
              Dim g As Byte = AcColor.ColorValue.G
              Dim b As Byte = AcColor.ColorValue.B
              Dim Color As Drawing.Color = Drawing.Color.FromArgb(r, g, b)

              cellBackground = New SolidBrush(Color)

              graphics.FillRectangle(cellBackground, ColorBoxRect)
              graphics.DrawRectangle(Pens.Black, ColorBoxRect)
              graphics.DrawString(AcColor.ToString, cellStyle.Font, System.Drawing.Brushes.Black, TextBoxRect)

              cellBackground.Dispose()


            End If
          End If
  End Sub

End Class

Public Class AcColorColumn
  Inherits DataGridViewColumn

  Public Sub New()
    MyBase.CellTemplate = New AcColorCell
  End Sub

End Class


As below, the code for the lineweight control

Public Class AcLineweightCell
  Inherits Windows.Forms.DataGridViewTextBoxCell

  'skip the following while debugging
  <DebuggerNonUserCode()> _
  Protected Overrides Sub Paint(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, ByVal cellBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, ByVal cellState As System.Windows.Forms.DataGridViewElementStates, ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts)
    MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)

    If Me.RowIndex < 0 Then Exit Sub

    If Not Me.Value Is DBNull.Value Then
      If Me.Value <> "" Then
        'Get value of cell
        Dim cellvalue As String = Me.Value

        'Get AutoCAD lineweight of value
        Dim lwconv As AcDb.LineWeightConverter = New AcDb.LineWeightConverter()
        Dim lw As AcDb.LineWeight = Nothing

        'Get the number of pixels that represent the lineweight
        Dim px As Integer = GetLineweightPixel(cellvalue)

        'Get rectangle where we can draw the lineweight
        Dim lwrect As New Rectangle(cellBounds.X, cellBounds.Y, cellBounds.Width - 1, px)
        lwrect.Width = 70
        lwrect.Height = px

        'Offset the rectangle from the top of the cell to center the lineweight display
        lwrect.Offset(0, Math.Round(cellBounds.Height / 2) - CInt(Math.Round(px / 2)))
        'Get rectangle where we can draw the cell value
        'Dim txrect As New RectangleF(cellBounds.X, lwrect.Width + 4, cellBounds.Width - 1, cellBounds.Height - 1)

        Dim newfont As New Font("Tahoma", 8.25, FontStyle.Regular, GraphicsUnit.Pixel)


        Dim cellBackground As New SolidBrush(Color.Black)
        graphics.FillRectangle(cellBackground, lwrect)

        cellBackground.Dispose()

      End If

    End If

  End Sub


black holes happened when God divided by zero

AnswerRe: First Question - Problem repainting datagridview Pin
Mycroft Holmes28-Dec-08 16:29
professionalMycroft Holmes28-Dec-08 16:29 
QuestionPDF file to Crystal Reports converter Pin
jigneshDPatel26-Dec-08 1:30
jigneshDPatel26-Dec-08 1:30 
AnswerRe: PDF file to Crystal Reports converter Pin
Dave Kreskowiak26-Dec-08 7:04
mveDave Kreskowiak26-Dec-08 7:04 
GeneralRe: PDF file to Crystal Reports converter Pin
jigneshDPatel26-Dec-08 16:38
jigneshDPatel26-Dec-08 16:38 
GeneralRe: PDF file to Crystal Reports converter Pin
Dave Kreskowiak26-Dec-08 17:27
mveDave Kreskowiak26-Dec-08 17:27 
QuestionMultiline listview Pin
JR21226-Dec-08 0:40
JR21226-Dec-08 0:40 
AnswerRe: Multiline listview Pin
Dave Kreskowiak29-Dec-08 4:38
mveDave Kreskowiak29-Dec-08 4:38 
GeneralRe: Multiline listview Pin
JR2124-Jan-09 23:21
JR2124-Jan-09 23:21 
GeneralRe: Multiline listview Pin
Dave Kreskowiak5-Jan-09 1:18
mveDave Kreskowiak5-Jan-09 1:18 
GeneralRe: Multiline listview Pin
JR2125-Jan-09 1:29
JR2125-Jan-09 1:29 
AnswerRe: Multiline listview Pin
derekbeacroft17-Jun-13 7:20
derekbeacroft17-Jun-13 7:20 
GeneralRe: Multiline listview Pin
JR21218-Jun-13 4:49
JR21218-Jun-13 4:49 
QuestionHow can refresh DB ??? Pin
JC.KaNNaN25-Dec-08 21:48
JC.KaNNaN25-Dec-08 21:48 
AnswerRe: How can refresh DB ??? Pin
Dave Kreskowiak26-Dec-08 7:00
mveDave Kreskowiak26-Dec-08 7:00 
AnswerRe: How can refresh DB ??? Pin
Nanda_MR26-Dec-08 18:13
Nanda_MR26-Dec-08 18:13 
QuestionMigration issue from VB6 to VB.Net Pin
Sree Nivas25-Dec-08 19:20
Sree Nivas25-Dec-08 19:20 
AnswerRe: Migration issue from VB6 to VB.Net Pin
Dave Kreskowiak26-Dec-08 6:59
mveDave Kreskowiak26-Dec-08 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.