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,

        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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
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).
        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
            intItems = dtTXDetail.Rows.Count
        End If

Open in new window

JDL129Author Commented:

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

JDL129, we wont be written the whole program her, would we? :) YOu need to read some basic info about how ADO.NET works if you think of doing some database programming.

Your data source cannot be the query, your data source (DBMS) can be SQL server, Orable, MySql, Access database, etc. Based on the DBMS you will choose appropriate objects. I will post bellow the example for MSSQL server (if using Access, you will use OleDbDataAdapter instead). Aslo note that you need a valid Sql connection (or OleDbConnection, if using MS Access).

Considering the exception you are receiving, it means that some variable is declared twice. Check your code to see which variable is that.

Dim da As New SqlDataAdapter("Select * from tblTXDetail where TXNum = " & Val(me.lblTXNum.text) & " category <> 'TAX' order by ID Desc.", sqlConnection)
dim dtTXDetail As new DataTable();

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JDL129Author Commented:
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,

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.