Problemas Com Alguns Eventos Simples

19/08/2007

0

Tipo Montei um eskeminha que pega quantidade, descrição, preço unitario e o total.. e joga em um Data Grid..

Ai eu fiz assim o Quantidade era um txt, descrição um ComboBox, unitario e total um txt tb...

eu digitava a quantidade escolhia o produto na Combo e tinha q colocar o preço no unitario e quando o foco passava pro total ja aparecia o total..

Mas eu num keria mais digita keria que esse unitario fosse uma combo que ja aparecia o preço la conforme com o index da descrição...

Mas eu num consigo vo posta as partes do codigo.....


Colored

Colored

Responder

Posts

19/08/2007

Colored

Public Class Form1
Inherits System.Windows.Forms.Form
Dim total As Single
Dim datItens As New DataTable
Dim dsItens As New DataSet
Dim novalinha As DataRow

#Region ´ Windows Form Designer generated code ´

Public Sub New()
MyBase.New()

´This call is required by the Windows Form Designer.
InitializeComponent()

´Add any initialization after the InitializeComponent() call

End Sub

´Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

´Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

´NOTE: The following procedure is required by the Windows Form Designer
´It can be modified using the Windows Form Designer.
´Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents DataGridTableStyle1 As System.Windows.Forms.DataGridTableStyle
Friend WithEvents colItem As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents colQtd As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents colDescr As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents colUnitario As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents colTotal As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents ComboBox2 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle
Me.colItem = New System.Windows.Forms.DataGridTextBoxColumn
Me.colQtd = New System.Windows.Forms.DataGridTextBoxColumn
Me.colDescr = New System.Windows.Forms.DataGridTextBoxColumn
Me.colUnitario = New System.Windows.Forms.DataGridTextBoxColumn
Me.colTotal = New System.Windows.Forms.DataGridTextBoxColumn
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.ComboBox2 = New System.Windows.Forms.ComboBox
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
´
´Label1
´
Me.Label1.Font = New System.Drawing.Font(´Microsoft Sans Serif´, 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(8, 16)
Me.Label1.Name = ´Label1´
Me.Label1.Size = New System.Drawing.Size(72, 23)
Me.Label1.TabIndex = 0
Me.Label1.Text = ´Quantidade´
´
´Label2
´
Me.Label2.Font = New System.Drawing.Font(´Microsoft Sans Serif´, 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(104, 16)
Me.Label2.Name = ´Label2´
Me.Label2.Size = New System.Drawing.Size(48, 23)
Me.Label2.TabIndex = 1
Me.Label2.Text = ´Material´
´
´Label3
´
Me.Label3.Font = New System.Drawing.Font(´Microsoft Sans Serif´, 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(280, 16)
Me.Label3.Name = ´Label3´
Me.Label3.Size = New System.Drawing.Size(48, 23)
Me.Label3.TabIndex = 2
Me.Label3.Text = ´Unitário´
´
´Label4
´
Me.Label4.Font = New System.Drawing.Font(´Microsoft Sans Serif´, 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(360, 16)
Me.Label4.Name = ´Label4´
Me.Label4.Size = New System.Drawing.Size(32, 23)
Me.Label4.TabIndex = 3
Me.Label4.Text = ´Total´
´
´TextBox1
´
Me.TextBox1.Location = New System.Drawing.Point(8, 32)
Me.TextBox1.Name = ´TextBox1´
Me.TextBox1.Size = New System.Drawing.Size(64, 20)
Me.TextBox1.TabIndex = 4
Me.TextBox1.Text = ´´
´
´TextBox2
´
Me.TextBox2.Location = New System.Drawing.Point(280, 32)
Me.TextBox2.Name = ´TextBox2´
Me.TextBox2.Size = New System.Drawing.Size(56, 20)
Me.TextBox2.TabIndex = 5
Me.TextBox2.Text = ´´
´
´TextBox3
´
Me.TextBox3.Location = New System.Drawing.Point(360, 32)
Me.TextBox3.Name = ´TextBox3´
Me.TextBox3.Size = New System.Drawing.Size(104, 20)
Me.TextBox3.TabIndex = 6
Me.TextBox3.Text = ´´
´
´ComboBox1
´
Me.ComboBox1.Items.AddRange(New Object() {´Monitor´, ´Impressora´, ´Mouse´, ´Teclado´, ´Gravador de Dvd´, ´Roteador´})
Me.ComboBox1.Location = New System.Drawing.Point(96, 32)
Me.ComboBox1.Name = ´ComboBox1´
Me.ComboBox1.Size = New System.Drawing.Size(160, 21)
Me.ComboBox1.TabIndex = 7
´
´DataGrid1
´
Me.DataGrid1.DataMember = ´´
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 80)
Me.DataGrid1.Name = ´DataGrid1´
Me.DataGrid1.Size = New System.Drawing.Size(464, 104)
Me.DataGrid1.TabIndex = 8
Me.DataGrid1.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1})
´
´DataGridTableStyle1
´
Me.DataGridTableStyle1.DataGrid = Me.DataGrid1
Me.DataGridTableStyle1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.colItem, Me.colQtd, Me.colDescr, Me.colUnitario, Me.colTotal})
Me.DataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGridTableStyle1.MappingName = ´Table1´
´
´colItem
´
Me.colItem.Format = ´´
Me.colItem.FormatInfo = Nothing
Me.colItem.HeaderText = ´Item´
Me.colItem.MappingName = ´Item´
Me.colItem.Width = 75
´
´colQtd
´
Me.colQtd.Format = ´´
Me.colQtd.FormatInfo = Nothing
Me.colQtd.HeaderText = ´Quantidade´
Me.colQtd.MappingName = ´Quantidade´
Me.colQtd.Width = 75
´
´colDescr
´
Me.colDescr.Format = ´´
Me.colDescr.FormatInfo = Nothing
Me.colDescr.HeaderText = ´Descrição´
Me.colDescr.MappingName = ´Descrição´
Me.colDescr.Width = 200
´
´colUnitario
´
Me.colUnitario.Format = ´´
Me.colUnitario.FormatInfo = Nothing
Me.colUnitario.HeaderText = ´Unitário´
Me.colUnitario.MappingName = ´Unitario´
Me.colUnitario.Width = 75
´
´colTotal
´
Me.colTotal.Format = ´´
Me.colTotal.FormatInfo = Nothing
Me.colTotal.HeaderText = ´Total´
Me.colTotal.MappingName = ´Total´
Me.colTotal.Width = 75
´
´Button1
´
Me.Button1.BackColor = System.Drawing.SystemColors.ControlDarkDark
Me.Button1.Font = New System.Drawing.Font(´Microsoft Sans Serif´, 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button1.ForeColor = System.Drawing.SystemColors.Window
Me.Button1.Location = New System.Drawing.Point(72, 208)
Me.Button1.Name = ´Button1´
Me.Button1.TabIndex = 9
Me.Button1.Text = ´Incluir´
´
´Button2
´
Me.Button2.BackColor = System.Drawing.SystemColors.ControlDarkDark
Me.Button2.Font = New System.Drawing.Font(´Microsoft Sans Serif´, 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button2.ForeColor = System.Drawing.SystemColors.Window
Me.Button2.Location = New System.Drawing.Point(160, 208)
Me.Button2.Name = ´Button2´
Me.Button2.TabIndex = 10
Me.Button2.Text = ´Excluir´
´
´Button3
´
Me.Button3.BackColor = System.Drawing.SystemColors.ControlDarkDark
Me.Button3.Font = New System.Drawing.Font(´Microsoft Sans Serif´, 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button3.ForeColor = System.Drawing.SystemColors.Window
Me.Button3.Location = New System.Drawing.Point(248, 208)
Me.Button3.Name = ´Button3´
Me.Button3.TabIndex = 11
Me.Button3.Text = ´Limpar´
´
´ComboBox2
´
Me.ComboBox2.Location = New System.Drawing.Point(344, 208)
Me.ComboBox2.Name = ´ComboBox2´
Me.ComboBox2.Size = New System.Drawing.Size(121, 21)
Me.ComboBox2.TabIndex = 12
´
´Form1
´
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.ClientSize = New System.Drawing.Size(496, 256)
Me.Controls.Add(Me.ComboBox2)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = ´Form1´
Me.Text = ´Form1´
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
´Carrega DataGrid de Itens
dsItens.Tables.Add(datItens)

dsItens.Tables(0).Columns.Add(´Item´, GetType(Integer))
dsItens.Tables(0).Columns(0).AutoIncrement = True
dsItens.Tables(0).Columns(0).AutoIncrementSeed = 1

dsItens.Tables(0).Columns(0).Unique = True

dsItens.Tables(0).Columns.Add(´Quantidade´, GetType(Decimal))
dsItens.Tables(0).Columns.Add(´Descrição´, GetType(String))
dsItens.Tables(0).Columns.Add(´Unitário´, GetType(Decimal))
dsItens.Tables(0).Columns.Add(´Total´, GetType(Decimal))

´===========================================================

DataGrid1.CaptionText = ´Itens de Vendas´
DataGrid1.DataSource = dsItens.Tables(0)


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
novalinha = dsItens.Tables(0).NewRow
novalinha(´Quantidade´) = TextBox1.Text
novalinha(´Descrição´) = ComboBox1.Text
novalinha(´Unitário´) = CSng(ComboBox2.Text)
novalinha(´Total´) = TextBox3.Text

dsItens.Tables(0).Rows.Add(novalinha)
dsItens.AcceptChanges()

TextBox1.Text = ´´
ComboBox1.Text = ´´
ComboBox2.Text = ´´
TextBox3.Text = ´´


End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rowselected() As DataRow
If DataGrid1.CurrentRowIndex <> -1 Then
rowselected = dsItens.Tables(0).Select _
(´Item = ´ & DataGrid1.Item(DataGrid1.CurrentRowIndex, 0) & ´ ´)

dsItens.Tables(0).Rows.Remove(rowselected(0))

End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
dsItens.Tables(0).Rows.Clear()
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.Items.Add(Format(349, ´R$ #,0.00´))
ComboBox2.Items.Add(Format(450, ´R$ ,0.00´))
ComboBox2.Items.Add(Format(60, ´R$ ,0.00´))
ComboBox2.Items.Add(Format(80, ´R$ ,0.00´))
ComboBox2.Items.Add(Format(178, ´R$ ,0.00´))
ComboBox2.Items.Add(Format(640, ´R$ ,0.00´))

ComboBox2.SelectedIndex = ComboBox1.SelectedIndex




End Sub

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If e.KeyChar = ChrW(13) Then

Dim qtd, unit As Single
qtd = CSng(TextBox1.Text)
unit = CSng(ComboBox2.Text)
total = ComboBox2.Text * TextBox1.Text
TextBox3.Text = Format(total, ´#,0.00´)
TextBox3.Focus()
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
End Class


Responder

19/08/2007

Colored

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
´Carrega DataGrid de Itens
dsItens.Tables.Add(datItens)

dsItens.Tables(0).Columns.Add(´Item´, GetType(Integer))
dsItens.Tables(0).Columns(0).AutoIncrement = True
dsItens.Tables(0).Columns(0).AutoIncrementSeed = 1

dsItens.Tables(0).Columns(0).Unique = True

dsItens.Tables(0).Columns.Add(´Quantidade´, GetType(Decimal))
dsItens.Tables(0).Columns.Add(´Descrição´, GetType(String))
dsItens.Tables(0).Columns.Add(´Unitário´, GetType(Decimal))
dsItens.Tables(0).Columns.Add(´Total´, GetType(Decimal))

´===========================================================

DataGrid1.CaptionText = ´Itens de Vendas´
DataGrid1.DataSource = dsItens.Tables(0)


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
novalinha = dsItens.Tables(0).NewRow
novalinha(´Quantidade´) = TextBox1.Text
novalinha(´Descrição´) = ComboBox1.Text
novalinha(´Unitário´) = CSng(ComboBox2.Text)
novalinha(´Total´) = TextBox3.Text

dsItens.Tables(0).Rows.Add(novalinha)
dsItens.AcceptChanges()

TextBox1.Text = ´´
ComboBox1.Text = ´´
ComboBox2.Text = ´´
TextBox3.Text = ´´


End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rowselected() As DataRow
If DataGrid1.CurrentRowIndex <> -1 Then
rowselected = dsItens.Tables(0).Select _
(´Item = ´ & DataGrid1.Item(DataGrid1.CurrentRowIndex, 0) & ´ ´)

dsItens.Tables(0).Rows.Remove(rowselected(0))

End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
dsItens.Tables(0).Rows.Clear()
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.Items.Add(Format(349, ´R$ #,0.00´))
ComboBox2.Items.Add(Format(450, ´R$ ,0.00´))
ComboBox2.Items.Add(Format(60, ´R$ ,0.00´))
ComboBox2.Items.Add(Format(80, ´R$ ,0.00´))
ComboBox2.Items.Add(Format(178, ´R$ ,0.00´))
ComboBox2.Items.Add(Format(640, ´R$ ,0.00´))

ComboBox2.SelectedIndex = ComboBox1.SelectedIndex




End Sub

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If e.KeyChar = ChrW(13) Then

Dim qtd, unit As Single
qtd = CSng(TextBox1.Text)
unit = CSng(ComboBox2.Text)
total = ComboBox2.Text * TextBox1.Text
TextBox3.Text = Format(total, ´#,0.00´)
TextBox3.Focus()
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
End Class


Responder

19/08/2007

Colored

e o segundo codigo... como faz pra apagar uma mensagem colokei o codigo errado antes


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar