Link to home
Start Free TrialLog in
Avatar of JDL129
JDL129

asked on

I need help upgrading a flexgrid to a data grid view

I need help changing the code from the VB6 code attached for a flexgrid to .net 2005 data grid view.
Code would be nice!!

Thanks in advance,

Jerry
MSFlexTXDetail.Clear
        With MSFlexTXDetail
            .Cols = 5
            .Rows = 2
            .TextMatrix(0, 1) = "ID"
            .TextMatrix(0, 2) = "Description"
            .TextMatrix(0, 3) = "Quantity"
            .TextMatrix(0, 4) = "Item Price"
            
            .ColAlignment(1) = flexAlignLeftBottom
            .ColAlignment(2) = flexAlignLeftBottom
            .ColAlignment(3) = flexAlignLeftBottom
            .ColAlignment(4) = flexAlignRightBottom
            .ColWidth(1) = 0
            .ColWidth(2) = 4500
            .ColWidth(3) = 1000
            .ColWidth(4) = 2000
        End With
        i = 1
       
       If rsTXDetail.RecordCount > 0 Then
          mcurTaxable = 0
          mcurTaxable2 = 0
            Do Until rsTXDetail.EOF
                  strDesc = Format(Trim(rsTXDetail.Fields("Desc")))
                  intQuantity = Format(Trim(rsTXDetail.Fields("Quan")))
                  curItemPrice = Trim(rsTXDetail.Fields("ItemPrice"))
                  If rsTXDetail.Fields("TAX") = 1 Then
                      mcurTaxable = mcurTaxable + curItemPrice
                      mcurTax = (mcurTaxable * gintTaxRate)
                  ElseIf rsTXDetail.Fields("TAX") = 2 Then
                      mcurTaxable2 = mcurTaxable2 + curItemPrice
                      mcurTax2 = (mcurTaxable2 * gintTaxRate2)
                  End If
                  gcurTax1 = mcurTaxable
                  gcurTax2 = mcurTaxable2
                  mcurSubtotal = mcurSubtotal + Trim(rsTXDetail.Fields("ItemPrice"))
            With MSFlexTXDetail
                .AddItem ""
                .TextMatrix(i, 1) = rsTXDetail!ID
                .TextMatrix(i, 2) = strDesc
                .TextMatrix(i, 3) = intQuantity
                .TextMatrix(i, 4) = Format(curItemPrice, "$##,###.00")
            End With
            intItems = intItems + 1

Open in new window

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

1) Drop a DataGridView on a form

2) Create or fill a DataTable.

3) Set the DataGridView.DataSource to the DataTable.

4) Define columns through the DataGridView designer, or in code.

5) Set row/column/cell styles.
as example I am using DataTable dtTXDetail instead of rsTXDetail, since in .NET you cannot use ADO objects (at least not recommended).
MSFlexTXDetail.Rows.Clear()
 
        If MSFlexTXDetail.ColumnCount = 0 Then
            With MSFlexTXDetail
                .Columns.Add("cID", "ID")
                .Columns.Add("cDescription", "Description")
                .Columns.Add("cQuantity", "Quantity")
                .Columns.Add("cItemPrice", "Item Price")
 
                .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft
                .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft
                .Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft
                .Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight
 
                .Columns(0).Width = 0
                .Columns(1).Width = 4500
                .Columns(2).Width = 1000
                .Columns(3).Width = 2000
 
                .RowCount = 2
            End With
        End If
 
        Dim dtTXDetail As New DataTable()
 
        If dtTXDetail.Rows.Count > 0 Then
 
            Dim mcurTaxable As Double = 0
            Dim mcurTaxable2 As Double = 0
 
            For Each dr As DataRow In dtTXDetail.Rows
                Dim strDesc As String = Trim(dr("Desc"))
                Dim intQuantity As Integer = dr("Quan")
                Dim curItemPrice As Double = dr("ItemPrice")
 
                Select Case dr("TAX")
                    Case 1
                        mcurTaxable = mcurTaxable + curItemPrice
                        mcurTax = (mcurTaxable * gintTaxRate)
                    Case 2
                        mcurTaxable2 = mcurTaxable2 + curItemPrice
                        mcurTax2 = (mcurTaxable2 * gintTaxRate2)
                End Select
 
                gcurTax1 = mcurTaxable
                gcurTax2 = mcurTaxable2
                mcurSubtotal += dr("ItemPrice")
 
                With MSFlexTXDetail
                    .Rows.Add(dr("ID"), strDesc, intQuantity, Format(curItemPrice, "$##,###.00"))
                End With
            Next
 
            intItems = dtTXDetail.Rows.Count
        End If

Open in new window

Avatar of JDL129
JDL129

ASKER

Priest04:

Thanks for your post!!
My data source Is:"Select * from tblTXDetail where TXNum = " & Val(me.lblTXNum.text) & " category <> 'TAX' order by ID Desc."
How would one select the data source with the data table?

Each of the three variables has an error message: "Variable strDesc hides a variable in an enclosing block"
Any Ideas?

Thanks again for your help!!

Jerry
ASKER CERTIFIED SOLUTION
Avatar of Priest04
Priest04
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JDL129

ASKER

Priest04,
Nope, not writing the whole program.  I am in the process of converting a vb6 app into .net and am running into a couple of learning curves.

Thanks for your post,

Jerry