Rectangle 27 6

Public Class Form1
    Private boxes(5) As TextBox

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim newbox As TextBox
        For i As Integer = 1 To 5 'Create a new textbox and set its properties26.27.
        newbox = New TextBox
        newbox.Size = New Drawing.Size(100, 20)
        newbox.Location = New Point(10, 10 + 25 * (i - 1))
        newbox.Name = "TextBox" & i
        newbox.Text = newbox.Name   'Connect it to a handler, save a reference to the array & add it to the form control.
        AddHandler newbox.TextChanged, AddressOf TextBox_TextChanged
        boxes(i) = newbox
        Me.Controls.Add(newbox)
        Next
    End Sub

    Private Sub TextBox_TextChanged(sender As System.Object, e As System.EventArgs)
        'When you modify the contents of any textbox, the name of that textbox
        'and its current contents will be displayed in the title bar

        Dim box As TextBox = DirectCast(sender, TextBox)
        Me.Text = box.Name & ": " & box.Text
    End Sub
End Class

How to programmatically add controls to a form in VB.NET - Stack Overf...

vb.net
Rectangle 27 1

With formview1
    Dim txtbox1Value as string = directcast(.findcontrol("textbox1"),textbox).Text
    Dim dropdownlist1Value as string = directcast(.FindControl("dropdownlist1"), DropDownList).SelectedValue
    if txtbox1Value > "0" Then
       if dropdownlist1Value <= "0" Then
           ' Error
       End If
       If dropdownlist1Value >= "100" Then
           ' Another error
       End If
    End If
    ' etc.
End With

The idea: get all the values you need to test in a convenient form up front, then implement your logic. This will make your logic simpler because you won't be distracted by the finding-and-casting you have to do.

Actually, you could wrap all that in the ServerValidate event of a CustomValidator.

Not familiar with the servervalidate event. Let me do some research and get back with you on that. However.. Your with event as mentioned above. Where would you think that would go?

after reading I see this is based on server side validation. Wouldn't I want this to be client side? If so or if not. Could you or someone explain why

directcast(formview1.findcontrol("textbox1"), textbox).text

You can do any of the following: write a client validation script for a CustomValidator control; write a custom validator from scratch, including client code; write your own validation routine in jQuery or a similar framework.

This is in the right step but now fo0r some reason my textbox's are returning 0's for their values which I initially set. A whole nother issue.......

vb.net - Validate Dropdown list selected value > 0 if asp.net form tex...

asp.net vb.net jquery-validate validation html-select
Rectangle 27 0

Public Class Form1
    Private boxes(5) As TextBox

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim newbox As TextBox
        For i As Integer = 1 To 5 'Create a new textbox and set its properties26.27.
        newbox = New TextBox
        newbox.Size = New Drawing.Size(100, 20)
        newbox.Location = New Point(10, 10 + 25 * (i - 1))
        newbox.Name = "TextBox" & i
        newbox.Text = newbox.Name   'Connect it to a handler, save a reference to the array & add it to the form control.
        AddHandler newbox.TextChanged, AddressOf TextBox_TextChanged
        boxes(i) = newbox
        Me.Controls.Add(newbox)
        Next
    End Sub

    Private Sub TextBox_TextChanged(sender As System.Object, e As System.EventArgs)
        'When you modify the contents of any textbox, the name of that textbox
        'and its current contents will be displayed in the title bar

        Dim box As TextBox = DirectCast(sender, TextBox)
        Me.Text = box.Name & ": " & box.Text
    End Sub
End Class

How to programmatically add controls to a form in VB.NET - Stack Overf...

vb.net
Rectangle 27 0

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
    Dim control As Control = Me.Controls("Button1")
    Select Case control.GetType
        Case GetType(Button)
            Dim btn As Button = DirectCast(control, Button)
            With btn
                .Text = "hi"
            End With
        Case GetType(Label)
            Dim lbl As Label = DirectCast(control, Label)
            With lbl
                .Text = "hi"
            End With
        Case Else 'etc
    End Select
End Sub

vb.net - accessing multiple form controls using a variable for the nam...

vb.net winforms vb.net-2010 vb6-migration
Rectangle 27 0

The code you're showing expects to find three Label controls on your form (or at least within the scope of the code being run), named lbl1, lbl2 and lbl3.

The error is telling you that one or more of these controls cannot be found.

directcast - vb.net string to object - Stack Overflow

vb.net directcast
Rectangle 27 0

Public Class Form1
    Private boxes(5) As TextBox

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim newbox As TextBox
        For i As Integer = 1 To 5 'Create a new textbox and set its properties26.27.
        newbox = New TextBox
        newbox.Size = New Drawing.Size(100, 20)
        newbox.Location = New Point(10, 10 + 25 * (i - 1))
        newbox.Name = "TextBox" & i
        newbox.Text = newbox.Name   'Connect it to a handler, save a reference to the array & add it to the form control.
        AddHandler newbox.TextChanged, AddressOf TextBox_TextChanged
        boxes(i) = newbox
        Me.Controls.Add(newbox)
        Next
    End Sub

    Private Sub TextBox_TextChanged(sender As System.Object, e As System.EventArgs)
        'When you modify the contents of any textbox, the name of that textbox
        'and its current contents will be displayed in the title bar

        Dim box As TextBox = DirectCast(sender, TextBox)
        Me.Text = box.Name & ": " & box.Text
    End Sub
End Class

How to programmatically add controls to a form in VB.NET - Stack Overf...

vb.net
Rectangle 27 0

Private Sub Button2_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)  
                                  Handles Pic1.DoubleClick,Pic2.DoubleClick, anyothercontrol.DoubleClick

       //(cast sender to picture control)
       If TypeOf sender Is PictureControl Then
         ControlName = DirectCast(sender, PictureBox).Name //use select case for further programming with control
       Else
         ControlName = DirectCast(sender, someothercontrol).Name
       End If
   End Sub

winforms - how to know on which control in panel double click is made ...

vb.net winforms panel picturebox double-click
Rectangle 27 0

With formview1
    Dim txtbox1Value as string = directcast(.findcontrol("textbox1"),textbox).Text
    Dim dropdownlist1Value as string = directcast(.FindControl("dropdownlist1"), DropDownList).SelectedValue
    if txtbox1Value > "0" Then
       if dropdownlist1Value <= "0" Then
           ' Error
       End If
       If dropdownlist1Value >= "100" Then
           ' Another error
       End If
    End If
    ' etc.
End With

The idea: get all the values you need to test in a convenient form up front, then implement your logic. This will make your logic simpler because you won't be distracted by the finding-and-casting you have to do.

Actually, you could wrap all that in the ServerValidate event of a CustomValidator.

Not familiar with the servervalidate event. Let me do some research and get back with you on that. However.. Your with event as mentioned above. Where would you think that would go?

after reading I see this is based on server side validation. Wouldn't I want this to be client side? If so or if not. Could you or someone explain why

directcast(formview1.findcontrol("textbox1"), textbox).text

You can do any of the following: write a client validation script for a CustomValidator control; write a custom validator from scratch, including client code; write your own validation routine in jQuery or a similar framework.

This is in the right step but now fo0r some reason my textbox's are returning 0's for their values which I initially set. A whole nother issue.......

vb.net - Validate Dropdown list selected value > 0 if asp.net form tex...

asp.net vb.net jquery-validate validation html-select
Rectangle 27 0

Private mytable As New Generic.Dictionary(Of String, List(Of String))

    Sub New()
        ' Dieser Aufruf ist fr den Windows Form-Designer erforderlich.
        InitializeComponent()

        mytable.Add("Object A", New List(Of String)(New String() {"Object A1", "Object A2", "Object A3"}))
        mytable.Add("Object B", New List(Of String)(New String() {"Object B1", "Object B2", "Object B3"}))
        mytable.Add("Object C", New List(Of String)(New String() {"Object C1", "Object C2", "Object C3"}))
        mytable.Add("Object D", New List(Of String)(New String() {"Object D1", "Object D2", "Object D3"}))
        mytable.Add("Object E", New List(Of String)(New String() {"Object E1", "Object E2", "Object E3"}))

        For Each key As String In mytable.Keys
            Me.clb1.Items.Add(key, False)
        Next
    End Sub

    Private Sub chkSelectAll_CheckedChanged(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles ChkSelectAll.CheckedChanged
        For i As Int32 = 0 To Me.clb1.Items.Count - 1
            Me.clb1.SetItemChecked(i, ChkSelectAll.Checked)
        Next
    End Sub

    Private Sub clb1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles clb1.ItemCheck
        Dim key As String = DirectCast(Me.clb1.Items(e.Index), String)
        If e.NewValue = CheckState.Checked Then
            For Each value As String In mytable(key)
                Me.Clb2.Items.Add(value, False)
            Next
        Else
            For Each value As String In mytable(key)
                Me.Clb2.Items.Remove(value)
            Next
        End If
    End Sub

EDIT: When you dont want to use Generics you can use Hashtable and Arraylist instead. My sample code is almost the same. Have a look:

Private mytable As New Hashtable()

    Sub New()
        ' Dieser Aufruf ist fr den Windows Form-Designer erforderlich.
        InitializeComponent()

        mytable.Add("Object A", New ArrayList(New String() {"Object A1", "Object A2", "Object A3"}))
        mytable.Add("Object B", New ArrayList(New String() {"Object B1", "Object B2", "Object B3"}))
        mytable.Add("Object C", New ArrayList(New String() {"Object C1", "Object C2", "Object C3"}))
        mytable.Add("Object D", New ArrayList(New String() {"Object D1", "Object D2", "Object D3"}))
        mytable.Add("Object E", New ArrayList(New String() {"Object E1", "Object E2", "Object E3"}))

        For Each key As String In mytable.Keys
            Me.clb1.Items.Add(key, False)
        Next
    End Sub

    Private Sub chkSelectAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkSelectAll.CheckedChanged
        For i As Int32 = 0 To Me.clb1.Items.Count - 1
            Me.clb1.SetItemChecked(i, ChkSelectAll.Checked)
        Next
    End Sub

    Private Sub clb1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles clb1.ItemCheck
        Dim key As String = DirectCast(Me.clb1.Items(e.Index), String)
        If e.NewValue = CheckState.Checked Then
            For Each value As String In mytable(key)
                Me.Clb2.Items.Add(value, False)
            Next
        Else
            For Each value As String In mytable(key)
                Me.Clb2.Items.Remove(value)
            Next
        End If
    End Sub

Thank you for your prompt response Tim but unfortunatley this routine is for work and the boss is one that insists that I only use arrays, arraylists, structures, and hashtables "for the sake of consistencey" grrr. I am currently in the process of applying your methodology to the tools that I am "allowed" to use. We'll see how it goes from here. ~8th

You can use a Hashtable and an Arraylist instead of my Dictionary and List(of String). Its almost the same.

vb.net - populating one checkedlistbox with another (checkedlistbox) -...

vb.net checkbox checkedlistbox populate
Rectangle 27 0

Dim btn as Button
Do Until IntegerCount = NumberOfRows
    btn=DirectCast(Controls("ButtonMeal" & IntegerCount.ToString),Button)
    btn.Text = "Hello"
    'AND MORE STUFF
Loop

Referring to Button on Form with String VB.NET - Stack Overflow

vb.net
Rectangle 27 0

Private Sub btnExportToExcel_Click(sender As Object, e As EventArgs) Handles btnExportToExcel.Click

    Dim StartDate As Date = DateTimePicker1.Value
    Dim EndDate As Date = DateTimePicker2.Value
    Dim worker = selectedWorker.FullName


    Dim xlApp As Microsoft.Office.Interop.Excel.Application
    Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
    Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
    Dim misValue As Object = System.Reflection.Missing.Value
    Dim i As Integer
    Dim j As Integer

    xlApp = New Microsoft.Office.Interop.Excel.Application
    xlWorkBook = xlApp.Workbooks.Add(misValue)
    xlWorkSheet = xlWorkBook.Sheets("sheet1")


    For i = 0 To dgvAppPlatite.RowCount - 2
        For j = 0 To dgvAppPlatite.ColumnCount - 1
            For k As Integer = 1 To dgvAppPlatite.Columns.Count
                xlWorkSheet.Cells(1, k) = dgvAppPlatite.Columns(k - 1).HeaderText
                xlWorkSheet.Cells(i + 2, j + 1) = dgvAppPlatite(j, i).Value.ToString()
            Next
        Next
    Next

    'Freeze top Row .. dar inca nu-mi merge
    xlWorkSheet.Activate()
    xlWorkSheet.Application.ActiveWindow.FreezePanes = True
    Dim firstRow As Range = DirectCast(xlWorkSheet.Rows(1), Excel.Range)
    firstRow.Activate()
    firstRow.Select()
    'firstRow.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd, Type.Missing, True)

    xlWorkSheet.PageSetup.CenterFooter = "Incasari : " & Label5.Text & " si comision : " & Label6.Text

    xlWorkSheet.SaveAs("D:\Docs\Rapoarte\" & worker & " " & StartDate & " " & EndDate & ".xlsx")
    xlWorkBook.Close()
    xlApp.Quit()

    releaseObject(xlApp)
    releaseObject(xlWorkBook)
    releaseObject(xlWorkSheet)

    MsgBox("D:\Docs\Rapoarte\" & worker & " " & StartDate & " " & EndDate & ".xlsx")
End Sub

I tried your code and got the same error msg plus some other line as follows: Exception Details: ...To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access. Same error! Now when I try to add the ASP.NET account, it doesn't appear in the list.

Then your problem came from Microsoft.Office.Interop.Excel version .. 32-bit / 64 bit and also check on localhost what office driver do you have .. and check if you have rights to create file in your path ..

CristiC777,what could be wrong with my Microsoft.Office.Interop.Excel version? It does not have 32-bit or 64-bit version. As I mentioned in my question, my MS Office Professional 2010 version 14.0 is 64-bit and my Excel file has all rights.

Creating Excel report form VB.NET - Stack Overflow

vb.net
Rectangle 27 0

dim email as string = "your email"
dim pass as string = "your pass"

    Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://touch.facebook.com"), HttpWebRequest)
                postReq.Method = "GET"
                postReq.KeepAlive = True
                postReq.CookieContainer = logincookie
                postReq.ContentType = "application/x-www-form-urlencoded"
                postReq.UserAgent = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3"

                Dim postresponse As HttpWebResponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
                logincookie.Add(postresponse.Cookies)

                Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

                Dim infos As String = postreqreader.ReadToEnd

                '---------------------------

                Dim byteData As Byte() = encoding.GetBytes("lsd=&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&version=1&ajax=0&width=0&pxr=0&gps=0&m_ts=&li=&email=" & email.Replace("@", "%40") & "&pass=" & pass & "&login=Connexion")

                postReq = DirectCast(WebRequest.Create("https://touch.facebook.com/login.php?refsrc=https%3A%2F%2Ftouch.facebook.com%2F&refid=8"), HttpWebRequest)
                postReq.Method = "POST"
                postReq.KeepAlive = True
                postReq.CookieContainer = logincookie
                postReq.ContentType = "application/x-www-form-urlencoded"
                postReq.Referer = "https://touch.facebook.com/"
                postReq.UserAgent = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3"
                postReq.ContentLength = byteData.Length

                Dim postreqstream As Stream = postReq.GetRequestStream()
                postreqstream.Write(byteData, 0, byteData.Length)
                postreqstream.Close()

                postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
                logincookie.Add(postresponse.Cookies)

                postreqreader = New StreamReader(postresponse.GetResponseStream())

login - VB.NET HttpWebRequest POST - Stack Overflow

vb.net login httpwebrequest
Rectangle 27 0

Public Shared Function ByteToImage(ByVal blob() As Byte) As Bitmap
        Dim mStream As New MemoryStream
        Dim pData() As Byte = DirectCast(blob, Byte())
        mStream.Write(pData, 0, Convert.ToInt32(pData.Length))
        Dim bm As Bitmap = New Bitmap(mStream, False)
        mStream.Dispose()
        Return bm
    End Function
Private Function InsertImage(ByVal ImagePath As String, ByVal oIDNum As String) As Boolean
    Dim iPhoto() As Byte = jwImage.FileImageToByte(ImagePath)
    Dim xBool As Boolean = False
    Using xConn As New MySqlConnection(ConnectionClass.ConnectionString)
        Try
            Dim xComm As New MySqlCommand
            With xComm
                .CommandText = "InsertImage"
                .Connection = xConn
                .CommandType = CommandType.StoredProcedure

                .Parameters.AddWithValue("xID", oIDNum)
                .Parameters.AddWithValue("xImage", iPhoto)
            End With

            xConn.Open()
            xComm.ExecuteNonQuery()
            xComm.Dispose()
            xBool = True
        Catch ex As MySqlException
            MessageBox.Show(ex.Message, "MySQL Error: " & ex.Number, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            xBool = False
        End Try
    End Using

    Return xBool
End Function

Hi Thanks Just want to know what is "jwImage" is it a PictureBox ID?

Can you please explain this line Dim iPhoto() As Byte = jwImage.FileImageToByte(ImagePath) Also when I will call this function "ByteToImage"

@Pankaj jwImage is a name of a class. FileImageToByte as the name says, it converts an Image into Byte Array.

.net - How to save PictureBox Image to SQL in VB.NET ( Windows Form ) ...

.net vb.net winforms picturebox
Rectangle 27 0

For Each Cntrl As Control In PanelName.Controls

Next

If all you have is the name of the panel and not the control reference, then you at least need to know which TabPage has the panel:

For Each ctrl As Control In TabControl1.TabPages(1).Controls("panel1").Controls

Next
Me.Controls.Find(PanelName, True)

to return the panel by name while searching child controls recursively.

Thanks LarsTech. This is what I need, but I did a horrible job describing the situation. I've edited my question, so hopefully it explains it better.

@JoeB Are these panels created dynamically? In your posted code, Me.Controls won't work since the panels are in your TabPage.Controls collection.

Thanks LarsTech. the .Find helped me enough to get it done.

VB.Net Form DirectCast on Forms.Panel - Stack Overflow

vb.net
Rectangle 27 0

Private Sub btnExportToExcel_Click(sender As Object, e As EventArgs) Handles btnExportToExcel.Click

    Dim StartDate As Date = DateTimePicker1.Value
    Dim EndDate As Date = DateTimePicker2.Value
    Dim worker = selectedWorker.FullName


    Dim xlApp As Microsoft.Office.Interop.Excel.Application
    Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
    Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
    Dim misValue As Object = System.Reflection.Missing.Value
    Dim i As Integer
    Dim j As Integer

    xlApp = New Microsoft.Office.Interop.Excel.Application
    xlWorkBook = xlApp.Workbooks.Add(misValue)
    xlWorkSheet = xlWorkBook.Sheets("sheet1")


    For i = 0 To dgvAppPlatite.RowCount - 2
        For j = 0 To dgvAppPlatite.ColumnCount - 1
            For k As Integer = 1 To dgvAppPlatite.Columns.Count
                xlWorkSheet.Cells(1, k) = dgvAppPlatite.Columns(k - 1).HeaderText
                xlWorkSheet.Cells(i + 2, j + 1) = dgvAppPlatite(j, i).Value.ToString()
            Next
        Next
    Next

    'Freeze top Row .. dar inca nu-mi merge
    xlWorkSheet.Activate()
    xlWorkSheet.Application.ActiveWindow.FreezePanes = True
    Dim firstRow As Range = DirectCast(xlWorkSheet.Rows(1), Excel.Range)
    firstRow.Activate()
    firstRow.Select()
    'firstRow.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd, Type.Missing, True)

    xlWorkSheet.PageSetup.CenterFooter = "Incasari : " & Label5.Text & " si comision : " & Label6.Text

    xlWorkSheet.SaveAs("D:\Docs\Rapoarte\" & worker & " " & StartDate & " " & EndDate & ".xlsx")
    xlWorkBook.Close()
    xlApp.Quit()

    releaseObject(xlApp)
    releaseObject(xlWorkBook)
    releaseObject(xlWorkSheet)

    MsgBox("D:\Docs\Rapoarte\" & worker & " " & StartDate & " " & EndDate & ".xlsx")
End Sub

I tried your code and got the same error msg plus some other line as follows: Exception Details: ...To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access. Same error! Now when I try to add the ASP.NET account, it doesn't appear in the list.

Then your problem came from Microsoft.Office.Interop.Excel version .. 32-bit / 64 bit and also check on localhost what office driver do you have .. and check if you have rights to create file in your path ..

CristiC777,what could be wrong with my Microsoft.Office.Interop.Excel version? It does not have 32-bit or 64-bit version. As I mentioned in my question, my MS Office Professional 2010 version 14.0 is 64-bit and my Excel file has all rights.

Creating Excel report form VB.NET - Stack Overflow

vb.net
Rectangle 27 0

dataGridView1.ReadOnly = false and dataGridView1.enabled = true

Private Sub dataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs)
 If TypeOf e.Control Is TextBox Then
' Set the TextBoxCell to readonly
Dim textBoxCell As TextBox = DirectCast(e.Control, TextBox)
textBoxCell.[ReadOnly] = True
 End If
End Sub

I tryd that also but than i cant select a part of text with mouse pointer

@AntoonVanSleeuwen, Please check above code its working ....

Tanx m8 i whas realy stuck but your code is perfect

visual studio 2010 - Windows Forms Datagridview (Select part of text i...

vb.net visual-studio-2010 windows-forms-designer
Rectangle 27 0

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim caller As String = DirectCast(sender, Button).Name
    Dim f As New frmSearch(caller)
    f.Show()
End Sub

Note that I am not using the default instance of the search form, this is important.

In the search form add this code

Dim whoCalled As String '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Public Sub New(caller As String)
    InitializeComponent()
    whoCalled = caller
End Sub

The variable whoCalled will contain the name of the caller.

If you want to make it impossible to create the form without passing the data, then in the search form also add

Private Sub New()
    ' This call is required by the designer.
    InitializeComponent()
End Sub

vb.net - How can a called form get the caller ID or tag of the calling...

vb.net vb.net-2010