3/2/11

DataGridViewRow cell click

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick Dim r As New DataGridViewRow If DataGridView1.Rows.Count > 0 Then r = DataGridView1.Rows(e.RowIndex) TextBox1.Text = r.Cells(0).Value TextBox2.Text = r.Cells(1).Value TextBox3.Text = r.Cells(2).Value price.Text = r.Cells(3).Value / r.Cells(2).Value End If End Sub

Save Data Grid Data

If DataGridView1.Rows.Count > 0 Then Dim r As DataGridViewRow For Each r In DataGridView1.Rows Dim db As New DBAccess Dim strSQL As String strSQL = "INSERT INTO [dbo].[Table_2] ([name1] ,[id1]) VALUES ( '" & r.Cells(0).Value & "'," & r.Cells(3).Value & " )" db.ExecuteScalar(strSQL, Data.CommandType.Text) db.CloseDB() Next End If

color tree node on specific condition

color tree node on specific condition Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TreeView1.Nodes.Add("222") TreeView1.Nodes(0).Nodes.Add("ABC12") TreeView1.Nodes(0).Nodes.Add("ABC13") TreeView1.Nodes(0).Nodes.Add("ABC14") TreeView1.Nodes(0).Nodes(0).Nodes.Add("ABC121") TreeView1.Nodes(0).Nodes(0).Nodes(0).Nodes.Add("ABC122") TreeView1.Nodes(0).Nodes(0).Nodes(0).Nodes(0).Nodes.Add("222") TreeView1.Nodes(0).Nodes(0).Nodes(0).Nodes.Add("333") TreeView1.Nodes(0).Nodes(0).Nodes.Add("ABC123") TreeView1.Nodes(0).Nodes(1).Nodes.Add("ABC131") TreeView1.Nodes(0).Nodes(1).Nodes(0).Nodes.Add("222") TreeView1.Nodes(0).Nodes(2).Nodes.Add("ABC121") TreeView1.Nodes(0).Nodes(2).Nodes.Add("111") TreeView1.Nodes(0).Nodes.Add("222") TreeView1.ExpandAll() If TreeView1.Nodes.Count > 0 Then For Each tnode As TreeNode In TreeView1.Nodes nodechk(tnode) Next End If End Sub Sub nodechk(ByVal m11 As TreeNode) apply(m11) If m11.Nodes.Count > 0 Then For Each m1 In m11.Nodes nodechk(m1) Next End If End Sub Sub apply(ByVal m1 As TreeNode) If m1.Text = "ABC121" Then m1.BackColor = Color.OrangeRed m1.ForeColor = Color.White Dim f As Font = New Font("verdana", 9, FontStyle.Bold) m1.NodeFont = f End If If m1.Text = "222" Then m1.BackColor = Color.Green m1.ForeColor = Color.White Dim f As Font = New Font("verdana", 9, FontStyle.Bold) m1.NodeFont = f End If End Sub

On textbox key down /focus help shd open

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = Keys.F1 Then Panel1.Visible = True TextBox1.Enabled = False TextBox2.Focus() End If End Sub Private Sub TextBox2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Leave If TextBox2.Text <> "" Then Panel1.Visible = False TextBox1.Enabled = True TextBox1.Text = TextBox2.Text End If End Sub