VB.NET只想在DataGridView Select Query之间插入Dyanmically Coloumns [英] VB.NET Only Want To Insert Dyanmically Coloumns Between DataGridView Select Query

查看:83
本文介绍了VB.NET只想在DataGridView Select Query之间插入Dyanmically Coloumns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,



我开发了一个用于在DataGridView中显示库存的程序,我有两个表First Table有一些列: -



Product_code,Product_name,Product_Price,Product_Quantity,Product_Vat。



和第二张桌子有: -



Product_code,Product_name,Danger_Lavel。



现在,我希望DataGridView行显示如下标题: -



Hello Experts,

I developed a program for displaying stock in DataGridView, I have Two Tables First Table Has some columns:-

Product_code, Product_name, Product_Price, Product_Quantity, Product_Vat.

and the Second Table has:-

Product_code, Product_name, Danger_Lavel.

Now, I want The DataGridView Rows Displaying Like Below Headers:-

P_Code    | Item_Name    | Rate  | Qty.   | Vat    |





高于第一张表中的列,现在我在下一列中计算或显示第一行的数量(Rate * Qty。)添加到DataGridView。



之后我想在DataGridView中显示第二个表数据



这意味着: - 当我想要表单加载事件时: -

Datagridview加载第一个表数据然后我添加一些新列到DataGridView

然后我想显示第二表数据。



我的查询在这里显示数据......和完整代码。





above Columns from first table, now I calculate or show amount of first row (Rate * Qty.) in next columns and add to DataGridView.

After That I want To Display Second Table Data In DataGridView

that mean:- When Form load event I want To:-
Datagridview Load First Table Data and Then After That I Add Some New Columns To DataGridView
and after that I want to Display Second Table Data.

My Query is Here To Display Data...... and Full Code.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblGrand.Text = ""
        DGridStoc.Columns.Clear()
        Dim commM55 As New OleDbCommand
        Dim datadM55 As New OleDbDataAdapter
        Dim Mdt55 As New DataTable
        Dim lev, amt, netamt As New DataGridViewTextBoxColumn
        If co.State = ConnectionState.Closed Then
            co.ConnectionString = "Provider = Microsoft.Jet.Oledb.4.0; Data Source = D:\InventSys\InveoSystem.mdb;" & "Jet OLEDB:Database Password=abstractinnadmin"
            co.Open()
        End If
        commM55.CommandText = "Select s.PCode, s.ProductName, s.PQuantity, s.PRate, s.VatPer, c.LevelValue from TblSTOCKING s, TblCodeList c Where s.PCode = c.PCode"
        commM55.CommandType = CommandType.Text
        datadM55.SelectCommand = commM55
        datadM55.SelectCommand.Connection = co
        datadM55.Fill(Mdt55)
        DGridStoc.DataSource = Mdt55
        DGridStoc.DataBindings.Clear()
        DGridStoc.Columns(0).HeaderText = "Category"
        DGridStoc.Columns(0).Width = 140
        DGridStoc.Columns(1).HeaderText = "Product Name"
        DGridStoc.Columns(1).Width = 350
        DGridStoc.Columns(2).HeaderText = "QTY."
        DGridStoc.Columns(2).Width = 100
        DGridStoc.Columns(3).HeaderText = "Price"
        DGridStoc.Columns(3).Width = 100
        DGridStoc.Columns(4).HeaderText = "VAT %"
        DGridStoc.Columns(4).Width = 90
        DGridStoc.Columns(5).HeaderText = "DLavel"
        DGridStoc.Columns(5).Width = 100
        '------------------------------------------------
        'Columns Add In DGridStoc
        DGridStoc.Columns.Add(amt)              'Coloumn 6
        DGridStoc.Columns.Add(netamt)           'Coloumn 7
        DGridStoc.Columns.Add(lev)              'Coloumn 8
        amt.HeaderText = "Amount"
        amt.Name = "Amount1"
        amt.Width = 80
        netamt.HeaderText = "Total"
        netamt.Name = "NetAmt1"
        netamt.Width = 100
        lev.HeaderText = "Level"
        lev.Name = "Level1"
        lev.Width = 60
        Dim cl, q As Long
        Dim vatper, cal As Double
        vatper = 0.0
        cal = 0.0
        For cl = 0 To Mdt55.Rows.Count - 1
            q = Val(DGridStoc.Rows(cl).Cells(2).Value)
            vatper = Val(DGridStoc.Rows(cl).Cells(4).Value)
            DGridStoc.Rows(cl).Cells(6).Value = DGridStoc.Rows(cl).Cells(2).Value * DGridStoc.Rows(cl).Cells(3).Value
            cal = Val(vatper) * Val(DGridStoc.Rows(cl).Cells(6).Value) / 100
            cal = Val(cal) + Val(DGridStoc.Rows(cl).Cells(6).Value)
            DGridStoc.Rows(cl).Cells(7).Value = cal.ToString
            If q < 5 Then
                DGridStoc.Rows(cl).DefaultCellStyle.Font = New Font("Arial", 9, FontStyle.Bold)
                DGridStoc.Rows(cl).DefaultCellStyle.BackColor = Color.LightYellow
                DGridStoc.Rows(cl).DefaultCellStyle.ForeColor = Color.Red
                DGridStoc.Rows(cl).Cells(8).Value = "Danger".ToString
            Else
                DGridStoc.Rows(cl).Cells(8).Value = "OK".ToString
            End If
        Next
        Try
            Dim grd, grd1 As Double
            Dim cpltr As Long
            For cpltr = 0 To DGridStoc.RowCount - 1
                grd = grd + Val(DGridStoc.Rows(cpltr).Cells(7).Value)
            Next
            grd1 = grd + Val(lblGrand.Text)
            lblGrand.Text = grd1.ToString
        Catch ex As Exception
            MsgBox("Stock Not Found!", MsgBoxStyle.Information, "No Stock")
        End Try
'Right Align Numeric Columns
        DGridStoc.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DGridStoc.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DGridStoc.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DGridStoc.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DGridStoc.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        co.Close()
    End Sub
End Class  



此代码完美但我想显示TblSTOCKING仅启动四列ie

PCode,ProductName,PQuantity,PRate from First Table然后添加我自己的动态列然后TblCodeList表一列后动态列添加......



谢谢高级....................


This Code is Perfect But I Want To Display TblSTOCKING Only Starting Four Columns i.e.
PCode, ProductName, PQuantity, PRate from First Table and Then Add My own Dynamically Columns and then TblCodeList Table One Columns After Dynamically Columns Add......

Thanks In Advanced....................

推荐答案

DGV一次只能绑定到一个源。



解决方案是创建一个包含所需列的新集合或DataTable。您可以使用DataView对象或任何IEnumerable集合来执行此操作。例如,您可以创建一个如下所示的新视图:

The DGV can only be bound to one source at a time.

The solution is to create a new collection or DataTable with all of the columns you want. You can do this either with a DataView object or any IEnumerable collection. For example, you could create a new view like this:
Dim orders As DataTable = dataSet.Tables("SalesOrderHeader")

Dim query = From order In orders.AsEnumerable()
    Where order.Field(Of Boolean)("OnlineOrderFlag") = True
    Order By order.Field(Of Decimal)("TotalDue")
    Select order

Dim view As DataView = query.AsDataView()

bindingSource1.DataSource = view


这篇关于VB.NET只想在DataGridView Select Query之间插入Dyanmically Coloumns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆