在datagridview中添加Col [英] Adding Col in datagridview

查看:110
本文介绍了在datagridview中添加Col的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有第4栏和第5栏,我想在colm 7中显示它们



ex。

名称Col4 col5 col6总计

Stephen 2 3 6

JOhn 5 9 11



这是我到目前为止的事情



Dim col1 As Integer

Dim col2 As Integer

Dim col3 As Integer

Private Sub dataGridView1_CellLeave(sender As Object,e As DataGridViewCellEventArgs)

如果e.ColumnIndex = 4那么

col1 = Integer.Parse(dataGridView1(1,e.RowIndex).Value .ToString())

col2 = Integer.Parse(dataGridView1(2,e.RowIndex).Value.ToString())

col3 = col1 + col2;

dataGridView1(3,e.RowIndex).Value =(col3).ToString()

结束如果

结束Sub

I have Columns 4 5 and 6 and i want to display them in colm 7

ex.
Name Col4 col5 col6 Total
Stephen 2 3 6
JOhn 5 9 11

this is what i have so far

Dim col1 As Integer
Dim col2 As Integer
Dim col3 As Integer
Private Sub dataGridView1_CellLeave(sender As Object, e As DataGridViewCellEventArgs)
If e.ColumnIndex = 4 Then
col1 = Integer.Parse(dataGridView1(1,e.RowIndex).Value.ToString())
col2 = Integer.Parse(dataGridView1(2,e.RowIndex).Value.ToString())
col3=col1+ col2;
dataGridView1(3, e.RowIndex).Value = (col3).ToString()
End If
End Sub

推荐答案

你可以试试这个



Imports System.Data.OleDb

Public Class help

Dim con As OleDbConnection

Dim cmd作为OleDbComm并且

Dim adp作为OleDbDataAdapter





Private Sub Button1_Click(发送者为对象,e为EventArgs)句柄Button1.Click

con = New OleDbConnection(Provider = Microsoft.jet.oledb.4.0; data source = D:\ Database3.mdb)

con.Open ()

Dim qry As String

qry =INSERT INTO total([name],[sal1],[sal2],[sal3],[total])VALUES ('&TextBox1.Text&',&TextBox2.Text&,&TextBox3.Text&,&TextBox4.Text&,&Val(TextBox2.Text)+ Val(TextBox3.Text) + Val(TextBox4.Text)&)

cmd =新的OleDbCommand(qry,con)

cmd.ExecuteNonQuery()

MsgBox (已添加总额)

End Sub
U can try this

Imports System.Data.OleDb
Public Class help
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim adp As OleDbDataAdapter


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
con = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=D:\Database3.mdb")
con.Open()
Dim qry As String
qry = "INSERT INTO total( [name], [sal1], [sal2] , [sal3], [total]) VALUES('" & TextBox1.Text & "' ," & TextBox2.Text & " ," & TextBox3.Text & "," & TextBox4.Text & "," & Val(TextBox2.Text) + Val(TextBox3.Text) + Val(TextBox4.Text) & ")"
cmd = New OleDbCommand(qry, con)
cmd.ExecuteNonQuery()
MsgBox("Total Added ")
End Sub


http:/ /www.dotnetperls.com/datagridview-vbnet [ ^ ]



http:// vb.net-informations.com/datagridview/vb.net_datagridview_tutorial.htm [ ^ ]



查看此链接对您有帮助..
http://www.dotnetperls.com/datagridview-vbnet[^]

http://vb.net-informations.com/datagridview/vb.net_datagridview_tutorial.htm[^]

view this links it's help full to you..


这篇关于在datagridview中添加Col的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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