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

JDL129Asked:
Who is Participating?
 
Priest04Connect With a Mentor Commented:
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();
 
da.Fill(dtTXDetail);

Open in new window

0
 
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.
0
 
Priest04Commented:
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

0
 
JDL129Author Commented:
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
0
 
JDL129Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.