Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ต้องการทราบผลรวมจากคอลั่มใน Datagrid ขอทราบแนวทางหรือโค๊ดหน่อยครับ



 

ต้องการทราบผลรวมจากคอลั่มใน Datagrid ขอทราบแนวทางหรือโค๊ดหน่อยครับ

 



Topic : 131725



โพสกระทู้ ( 58 )
บทความ ( 0 )



สถานะออฟไลน์




ต้องการทราบผลรวมใน datagrid ของตัวที่วง โดยให้ผลลัพย์ต่อด้านล่างสุดตรงลูกศรชี้ต้องไช้โค๊ดยังไงครับ โค๊ด VB ครับ


dfdfdff



Tag : .NET, VB.NET, VS 2003 (.NET 1.1), VS 2005 (.NET 2.x), VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)









ประวัติการแก้ไข
2018-08-07 17:04:54
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-08-07 17:03:24 By : futurezax View : 839 Reply : 8
 

 

No. 1

Guest


Code
If DataGridView1.RowCount > 1 Then
Dim iTax As Integer = 0

For index As Integer = 0 To DataGridView1.RowCount - 1
iTax += Convert.ToInt32(DataGridView1.Rows(index).Cells(0).Value)
Next
Label2.Text = iTax
End If







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-07 18:43:35 By : DREAM
 


 

No. 2



โพสกระทู้ ( 58 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : DREAM เมื่อวันที่ 2018-08-07 18:43:35
รายละเอียดของการตอบ ::
ตอบความคิดเห็นที่ : 1 เขียนโดย : DREAM เมื่อวันที่ 2018-08-07 18:43:35
รายละเอียดของการตอบ ::
เกิด error แบบนี้ครับ
ฟหฟหฟหฟห



อันนี้โค๊ดทั้งหมดครับ ไม่รู้ว่าผมนำไปใส่ถูกเปล่า
Code (VB.NET)
Imports System.Data.SqlClient
Imports System.Threading
Imports System.Globalization

Public Class Form1

    Dim resp As MsgBoxResult

    Dim a1 As Integer = "10000"
    Dim a2 As Integer = "3000"
    Dim a3 As Integer = "13000"
    Dim a4 As Integer = "50000"

    Dim b1 As Integer = "11250"
    Dim b2 As Integer = "3250"
    Dim b3 As Integer = "14000"
    Dim b4 As Integer = "56000"

    Dim c1 As Integer = "12500"
    Dim c2 As Integer = "3500"
    Dim c3 As Integer = "16000"
    Dim c4 As Integer = "63000"

    Dim d1 As Integer = "13250"
    Dim d2 As Integer = "3750"
    Dim d3 As Integer = "17000"
    Dim d4 As Integer = "66000"

    Dim e1 As Integer = "14000"
    Dim e2 As Integer = "4000"
    Dim e3 As Integer = "18000"
    Dim e4 As Integer = "70000"

    Dim f1 As Integer = "15000"
    Dim f2 As Integer = "4000"
    Dim f3 As Integer = "19000"
    Dim f4 As Integer = "75000"

    Dim g1 As Integer = "16000"
    Dim g2 As Integer = "4500"
    Dim g3 As Integer = "20500"
    Dim g4 As Integer = "80000"

    Dim h1 As Integer = "20000"
    Dim h2 As Integer = "5000"
    Dim h3 As Integer = "25000"
    Dim h4 As Integer = "100000"

    Dim i1 As Integer = "22500"
    Dim i2 As Integer = "6000"
    Dim i3 As Integer = "28500"
    Dim i4 As Integer = "110000"

    Dim j1 As Integer = "25000"
    Dim j2 As Integer = "7000"
    Dim j3 As Integer = "32000"
    Dim j4 As Integer = "125000"

    Dim com As String = "Completed"
    Dim wai As String = "Waiting"


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim casee As String = ""



        If RB1.Checked Then
            txt1.Text = a1
            txt2.Text = a2
            txt3.Text = a3
            txt4.Text = a4
        ElseIf RB2.Checked Then
            txt1.Text = b1
            txt2.Text = b2
            txt3.Text = b3
            txt4.Text = b4
        ElseIf RB3.Checked Then
            txt1.Text = c1
            txt2.Text = c2
            txt3.Text = c3
            txt4.Text = c4
        ElseIf RB4.Checked Then
            txt1.Text = d1
            txt2.Text = d2
            txt3.Text = d3
            txt4.Text = d4
        ElseIf RB5.Checked Then
            txt1.Text = e1
            txt2.Text = e2
            txt3.Text = e3
            txt4.Text = e4
        ElseIf RB6.Checked Then
            txt1.Text = f1
            txt2.Text = f2
            txt3.Text = f3
            txt4.Text = f4
        ElseIf RB7.Checked Then
            txt1.Text = g1
            txt2.Text = g2
            txt3.Text = g3
            txt4.Text = g4
        ElseIf RB8.Checked Then
            txt1.Text = h1
            txt2.Text = h2
            txt3.Text = h3
            txt4.Text = h4
        ElseIf RB9.Checked Then
            txt1.Text = i1
            txt2.Text = i2
            txt3.Text = i3
            txt4.Text = i4
        ElseIf RB10.Checked Then
            txt1.Text = j1
            txt2.Text = j2
            txt3.Text = j3
            txt4.Text = j4
        End If


    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        nameasset()
        statussalary()
        change_all_column()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.Close()
    End Sub

    Private Sub change_all_column()
        Dim header() As String = {"รหัสงาน", "ชื่อ", "ค่าบริการ"}
        change_column_datagrid(DGV1, header)
    End Sub

    Private Sub nameasset()
        If cn.State = ConnectionState.Open Then cn.Close()
        'cn.ConnectionString = sql
        connect_open()

        Dim sql1 As String = "SELECT CUSTID,USER_ASSess FROM TBL_POLICY_SUCCESS"
        'Dim sql1 As String = "SELECT OFFICER_ID,FNAME_THAI FROM TBL_OFFICER"

        Dim da As New SqlDataAdapter(sql1, cn)


        Dim dt As New DataTable
        da.Fill(dt)

        With cbb1
            .DataSource = dt
            .DisplayMember = dt.Columns.Item("USER_ASSess").ColumnName
            .ValueMember = dt.Columns.Item("CUSTID").ColumnName

        End With
    End Sub

    Private Sub statussalary()
        If cn.State = ConnectionState.Open Then cn.Close()
        'cn.ConnectionString = sql
        connect_open()

        Dim sql1 As String = "SELECT cus,status FROM Status_Salary"
        'Dim sql1 As String = "SELECT OFFICER_ID,FNAME_THAI FROM TBL_OFFICER"

        Dim da As New SqlDataAdapter(sql1, cn)


        Dim dt As New DataTable
        da.Fill(dt)

        With cbb2
            .DataSource = dt
            .DisplayMember = dt.Columns.Item("status").ColumnName
            .ValueMember = dt.Columns.Item("cus").ColumnName

        End With
    End Sub



    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       
        names.Text = cbb1.Text
        sql = "select CERTIFICATE,NAME,TOTALPRICE from TBL_POLICY_SUCCESS where STATUS_REPORT1 = '" & cbb2.Text & "' AND TBL_POLICY_SUCCESS.USER_ASSess = '" & cbb1.Text & "'  "
        DGV1.DataSource = cmd_dataTable()

        ' AND TBL_POLICY_SUCCESS.SENT_REPORT_DATE like '" & dtp_1.Value.ToString("yyyy-MM-dd HH:mm:ss.ttt") & "'
    End Sub


    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        GirdToExcel(DGV1)
    End Sub

    Private Sub GirdToExcel(ByRef dgvw As DataGridView)
        Dim Appli As New Microsoft.Office.Interop.Excel.Application
        Dim Libro As Microsoft.Office.Interop.Excel.Workbook
        Dim Hoja As Microsoft.Office.Interop.Excel.Worksheet
        Dim col As Integer = DGV1.ColumnCount
        Dim row As Integer = DGV1.RowCount
        Libro = Appli.Workbooks.Add
        Hoja = Appli.Worksheets.Add()

        For i As Integer = 1 To col
            Hoja.Cells.Item(1, i) = DGV1.Columns(i - 1).Name.ToString
        Next
        For fila As Integer = 0 To row - 1
            For e As Integer = 0 To col - 1
                Hoja.Cells.Item(fila + 2, e + 1) = DGV1.Rows(fila).Cells(e).Value
            Next
        Next
        Hoja.Rows.Item(1).font.bold = 1
        Hoja.Rows.Item(1).horizontalAlignment = 3
        Hoja.Columns.AutoFit()
        Appli.Application.Visible = True
        Appli.Application.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMaximized
        Hoja = Nothing
        Libro = Nothing
        Appli = Nothing


    End Sub


    Private Sub DGV1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellContentClick
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If DGV1.RowCount > 1 Then
            Dim iTax As Integer = 0

            For index As Integer = 0 To DGV1.RowCount - 1
                iTax += Convert.ToInt32(DGV1.Rows(index).Cells(0).Value)
            Next
            Label5.Text = iTax
        End If
    End Sub
End Class




แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 09:53:22 By : futurezax
 

 

No. 3

Guest


ตอบความคิดเห็นที่ : 2 เขียนโดย : futurezax เมื่อวันที่ 2018-08-08 09:53:22
รายละเอียดของการตอบ ::
Debug ดูบรรทัดที่ error ว่าได้ค่าอะไรมา มันถูกไหม

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 10:30:00 By : DREAM
 


 

No. 4



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

iTax += Convert.ToInt32(DGV1.Rows(index).Cells(2).Value)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 11:02:02 By : lamaka.tor
 


 

No. 5



โพสกระทู้ ( 58 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 4 เขียนโดย : lamaka.tor เมื่อวันที่ 2018-08-08 11:02:02
รายละเอียดของการตอบ ::
อ่อได้ละครับผมลืมดูcell ขอบคุณครับ
แต่ถ้าอยากให้มันต่อท้ายล่างสุดตรง cell 2 ล่ะครับ



ประวัติการแก้ไข
2018-08-08 11:19:41
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 11:14:44 By : futurezax
 


 

No. 6



โพสกระทู้ ( 58 )
บทความ ( 0 )



สถานะออฟไลน์


ผลรวมสาามารถใช้ได้ครับสำหรับการค้นหาที่เจอตั้งแต่ 2 ตัวขึ้นไป แต่ปรากฎว่าพอเป็นงานที่เป็นแถวเดียวแบบรูป มันไม่ยอมส่งค่ามายังช่องยอดบริการทั้งหมดครับ

กกกกกก


ประวัติการแก้ไข
2018-08-08 11:35:30
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 11:34:31 By : futurezax
 


 

No. 7

Guest


ตอบความคิดเห็นที่ : 6 เขียนโดย : futurezax เมื่อวันที่ 2018-08-08 11:34:31
รายละเอียดของการตอบ ::
ก็ใน code DGV1.ROWSCOUNT > 1 ไง ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 11:47:56 By : DREAM
 


 

No. 8



โพสกระทู้ ( 58 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 7 เขียนโดย : DREAM เมื่อวันที่ 2018-08-08 11:47:56
รายละเอียดของการตอบ ::
ขอบคุณครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 12:57:58 By : futurezax
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการทราบผลรวมจากคอลั่มใน Datagrid ขอทราบแนวทางหรือโค๊ดหน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่