Results 1 to 2 of 2

Thread: Printing from datagrid only if row is ticked

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2018
    Posts
    8

    Printing from datagrid only if row is ticked

    Hello,
    I need help to printing a whole row when its checkbox is ticked from a datagrid.
    I have the checkbox in the datagrid at column 4.
    So far, i've only got the print button to print the whole array, not the selected rows. However, I do not know where to go from there.

    Code:
     ReDim Preserve arrTasks(intIndex - 1)
            Dim CompanyFont As New Font("Gill Sans Ultra Bold", 18)
            Dim HeadingFont As New Font("Adobe Gothic Std B", 10)
            Dim defaultText As New Font("Calibri (Body)", 10)
            Dim printStartPosition As New PointF(50, 50)
            Dim defTextX As Integer = 50
            Dim defID As Integer = 175
            Dim defMeal As Integer = 300
            Dim defCost As Integer = 575
            Dim defTextY As Integer = 60
            Dim arrRecSplit(2) As String
            e.Graphics.DrawImage(My.Resources.Logo, 670, 80)
            e.Graphics.DrawString("Song Huong Meal Receipt", CompanyFont, Brushes.Green, defTextX, 20)
            e.Graphics.DrawString("#ID", HeadingFont, Brushes.DarkBlue, defID, defTextY)
            e.Graphics.DrawString("Meal", HeadingFont, Brushes.DarkBlue, defMeal, defTextY)
            e.Graphics.DrawString("Cost", HeadingFont, Brushes.DarkBlue, defCost, defTextY)
            defTextY += 20 'Increments the y coordinate by 20
            'This loops through the array reading the record from order meal and spliting it into the fields, then printing the field content
            For i = 0 To intIndex - 1
                arrRecSplit = Split(arrTasks(i).ToString, "|") 'takes the content of the address array and splits it into 5 parts
                e.Graphics.DrawString(arrTasks(i).ID, defaultText, Brushes.Black, defID, defTextY) ' Prints Id
                e.Graphics.DrawString(arrTasks(i).Meal, defaultText, Brushes.Black, defMeal, defTextY) ' Prints meal
                e.Graphics.DrawString(arrTasks(i).Cost, defaultText, Brushes.Black, defCost, defTextY) ' Prints Cost
                defTextY += 20 'Increments the y coordinate by 20
            Next
    I think I need to put another loop, reading of the array then check if the rows cell(4) is tick or not.
    Any advice?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Printing from datagrid only if row is ticked

    I don't see any reference to any grid in there at all but no, you don't need a loop. At the point that you get the data from the grid, wherever that might be, you simply need an If statement to test the value in the fourth column. I'm not sure exactly how that should be done because I'm not sure exactly what the code that gets the data from the grid looks like but it won't be complex. Like I said, it's a simple If statement, i.e. if that column is checked in the current row then print the row.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width