I've been working on a Textbox that only accepts 0-9, Decimal Point, and the Backspace Keys. Also keeps it in the base form 0.00. Max value is 999999.99 can be set as needed. It works as expected, but I have to ask if I have remade the wheel. This sub is set as the KeyPress Event for the textboxes on the form and will not allow wrong KeyChar's to be entered. Any tips or criticisms welcome..

 ''' <summary>
    ''' Previews the Key stroke attempting to be entered into textbox
    ''' allows or disallows the key depending on the 
    ''' e.KeyChar, position, and Caret Position.
    ''' Only 0-9 a single decimal point and 2 places after the decimal.
    ''' The Backspace key is also allowed
    ''' Max Value = 999999.99
    ''' </summary>
    ''' <param name="sender">TextBox</param>
    ''' <param name="e"> Handled = true disallows Key :: Handled = False Allows Key
    ''' </param>
    ''' <remarks></remarks>
    Public Sub BoxKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)

        'allow Backspace and exit the sub no need to process further
        If e.KeyChar = Chr(8) Then e.Handled = False : Exit Sub

        Dim tb As TextBox = DirectCast(sender, TextBox) 'Get the TextBox. 

        'Fill Physical variables
        'Decimal Point(if present) Location :: If not present (-1)
        Dim point As Integer = tb.Text.IndexOf(".")
        Dim caretIndex As Integer = tb.SelectionStart 'Caret position
        Dim len As Integer = tb.Text.Length 'Length of text present already in textbox

        'Check if a digit has been entered
        If Not Char.IsDigit(e.KeyChar) Then e.Handled = True

        'If the Key ...
Begginnerdev commented: Nice work, friend! +9
ddanbe commented: Nice! +14

This is free Click Here

If you still can't find what's Checking Your CheckBox Try right-clicking on the CheckBox in Code and selecting "Find All References" go through each one and see where your CheckBox is being checked. It sounds like you have some code out of order. Also you could step through the code with the debugger to see when & where you are Checking the Mis-Behaved CheckBox.

Begginnerdev commented: It's not easy being cheesy. +8

You are creating a new DataSet each time you run this code so the table your DataGridView is using gets refreshed with only the record queried for.

You might try using the Datareader to fill the DataTable you're using for your DataGridViews DataSource.

You can create some variables to hold the values read from the DataReader then ad them to your DataTable
You should also use the BindingSource so its easier to refresh your DataGridView.

 Dim newRow As DataRow = ds.Tables("TableName").NewRow()

        newRow("FieldName1") = "SomeValue1"
        newRow("FieldName1") = "SomeValue2"

        ds.Tables("TableName").Rows.Add(newRow)

Give me a shout if you need help setting it up.

The text file with this post has one line of text and a newline. You can use either VBCRLF or VBNEWLINE

 Dim txt As String = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\newLine.txt")

 If txt.Contains(vbNewLine) Then
            MsgBox(txt.IndexOf(vbNewLine))
        End If

I may be off the edge of the map here but Why are you using the cmd.ExecuteReader to Insert values into a table when you should be using cmd.ExecuteNonQuery?

AndreRet commented: Same here, should have seen that coming :) +12
Nutster commented: I should have caught that. The wrong function is being called for an operation that does not return any rows. +3

Your updated xmlwill only have 1 table now if that is what you are desiring. I ran the code and it displays the way I understand you want. I added a little updating code to it

Public Class Form1
    Dim bs As New BindingSource
    Dim editFlag As Boolean = False
    Dim filepath As String = "text.xml"
    Dim deflection_dataset As New DataSet

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            deflection_dataset.ReadXml(filepath)
            bs.DataSource = deflection_dataset.Tables(0)
            Deflections_datagrid.DataSource = bs
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

    Private Sub btnSaveChanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveChanges.Click
        If editFlag Then
            Try
                deflection_dataset.WriteXml("Text.xml")
                editFlag = False
                MsgBox("Changes to the XML have been SAVED", MsgBoxStyle.Information, "SUCCESS")
            Catch ex As Exception
                MsgBox("CHANGES HAVE NOT BEEN SAVED", MsgBoxStyle.Critical, "FAILURE")
            End Try

        End If

    End Sub

    Private Sub Deflections_datagrid_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Deflections_datagrid.CellEndEdit
        editFlag = True
        bs.ResetBindings(False)

    End Sub
End Class

Not to beat a dead horse, but you could just call this Sub like the following:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call DoControls(Me)
    End Sub

    Private Sub DoControls(ByVal ctrlCont As Control)
        For Each ctrl As Control In ctrlCont.Controls
            If TypeOf ctrl Is CheckBox Then
                If TypeOf ctrl Is CheckBox AndAlso DirectCast(ctrl, CheckBox).Checked Then
                    If ctrl.Tag Is "Test" Then
                        DirectCast(ctrl, CheckBox).Checked = False
                    End If
                End If
            End If

            'If the ctrl has children, 
            'recall this Sub
            If ctrl.HasChildren Then
                DoControls(ctrl)
            End If
        Next
    End Sub
iFrolox commented: Worked :) Thank you +2

Have you thought of using an XML file instead of the CSV. You could take advantage of the DataSet.Read and DataSet.Write methods.

themaj commented: dell +1

You have no Single quotes around KMBPartNo

Dim SelectQry = "SELECT * FROM TblSupplierQuotes where TenderNo='" & Me.txtTenderRef.Text & "' AND KMBPartNo='" & Me.lbKMBPartNo.Text & "';"

I assuming the Return from

Private Function Req(ByVal Site As String, ByVal Met As String, Optional ByVal P As String = "") As String

is the source you are trying to put in a RichTextBox? If so just create a read only property in the YouTube Class and access it after the login and use it for your RichTextBox text. rtbSource is the RichTextBox.

Private m_resp As String

  Public ReadOnly Property Source() As String
    Get
      Return m_resp
    End Get

  End Property

Private Function Req(ByVal Site As String, ByVal Met As String, Optional ByVal P As String = "") As String
    Dim Response As String = String.Empty
    Try
      Dim R As HttpWebRequest = CType(HttpWebRequest.Create(Site), HttpWebRequest)
      R.Method = Met
      R.CookieContainer = Containa
      R.AllowAutoRedirect = True
      R.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0"
      R.ContentType = "application/x-www-form-urlencoded"
      R.ServicePoint.Expect100Continue = False
      If Met = "POST" Then
        R.ContentLength = P.Length
        Dim Wr As New StreamWriter(R.GetRequestStream(), System.Text.Encoding.Default)
        Wr.Write(P)
        Wr.Close()
      End If

      Dim Re As New StreamReader(R.GetResponse.GetResponseStream())
      Response = Re.ReadToEnd
      Re.Close()
    Catch
    End Try
  **  m_resp = Response**
    Return Response
  End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim Nick As String = txtUserName.Text
    Dim Pw As String = txtPassword.Text
    Dim B As New Youtube

    lblInfo.Text = ">> Trying to log in ..."
    If B.Login(Nick, Pw) Then

      lblInfo.Text = ">>> Login successfully!"
    Else
      lblInfo.Text = ">>> Login failed!"

    End If
    rtbSource.Text = B.Source
  End Sub

If this is wrong let me know.

If you put the call to the Youtube class in the Button Click event it should call all the functions/subs. I tried it but as i do not have a YouTube account I couldn't varify that it works only that I failed to log in.

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim Nick As String = txtUserName.Text
    Dim Pw As String = txtPassword.Text
    Dim B As New Youtube

    lblInfo.Text = ">> Trying to log in ..."
    If B.Login(Nick, Pw) Then
      lblInfo.Text = ">>> Login successfully!"
    Else : lblInfo.Text = ">>> Login failed!"
    End If

  End Sub
     Dim lines() As String
        lines = TextBox1.Lines
        Dim amper As Integer = 0
        For Each l In lines
          amper = l.IndexOf("@")
          MsgBox(l.Remove(amper, l.Length - amper))
        Next

I created a XLXM workbook added a simple macro that open a messagebox and puts the number 2 in B1 cell then saves the workbook as a XLSX file and does not save the 2 in cell B1 of the xlsm file. Here is the code. Hope this helps.

Imports Microsoft.Office.Interop
Imports System.IO

Public Class Form1
  Dim xlApp As Excel.Application
  Dim xlWorkBook As Excel.Workbook
  Dim xlWorkSheet As Excel.Worksheet

  Private Sub releaseObject(ByVal obj As Object)
    Try
      System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
      obj = Nothing
    Catch ex As Exception
      obj = Nothing
    Finally
      GC.Collect()
    End Try
  End Sub

  Private Sub btnMacro_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMacro_1.Click
    Dim fldr As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments

    xlApp = New Excel.ApplicationClass
    xlApp.DisplayAlerts = False
    xlWorkBook = xlApp.Workbooks.Open(fldr & "\book1.xlsm")
    xlWorkSheet = CType(xlWorkBook.Worksheets(Index:=1), Excel.Worksheet)
    xlApp.Run("Sheet1.RunMe")

    '~~>Save the workbook
    **xlWorkBook.SaveAs(Filename:=fldr & "\BOOK2.xlsx", FileFormat:=51)**

    'xlWorkSheet.SaveAs(fldr & "\TEST.xlsx", FileFormat:=51)

    '~~>Close the WorkBook and DO NOT Save Changes - FALSE
    xlWorkBook.Close(False)

    '~~> Quit the Excel Application
    xlApp.Quit()

    '~~> Clean Up
    releaseObject(xlApp)
    releaseObject(xlWorkBook)

  End Sub

End Class