Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all 27289 articles
Browse latest View live

vb.net backgroundworker CancelAsync not work

$
0
0
hi all dears

I have a stop problem in the backgroundworker, I use the following commands for backgroundworker:


Code:

Private Sub UnpackSystem_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles UnpackSystem.DoWork
    Dim worker As System.ComponentModel.BackgroundWorker = DirectCast(sender, System.ComponentModel.BackgroundWorker)
    For i As Integer = 1 To 100
        If worker.CancellationPending Then
            e.Cancel = True
            Exit For
        End If
        worker.ReportProgress(i, i & " iterations complete")
        Threading.Thread.Sleep(250)
        Dim oProcess As New Process()
        Dim oStartInfo As New ProcessStartInfo("cmd.exe", "/c bin\Imgtool\simg2img.exe tmp/system.img tmp/system.img.ext4")
        oStartInfo.WindowStyle = ProcessWindowStyle.Hidden
        oStartInfo.CreateNoWindow = True
        oStartInfo.UseShellExecute = False
        oStartInfo.RedirectStandardOutput = True
        oProcess.StartInfo = oStartInfo
        oProcess.Start()
        Dim sOutput As String
        Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
            sOutput = oStreamReader.ReadToEnd()
        End Using
        TextBox8.Invoke(Sub() TextBox8.AppendText(Environment.NewLine & sOutput))

    Next i

End Sub

Private Sub UnpackSystem_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles UnpackSystem.ProgressChanged
    Me.ProgressBar5.Value = e.ProgressPercentage
End Sub

Private Sub UnpackSystem_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles UnpackSystem.RunWorkerCompleted
    If e.Cancelled = True Then
        TextBox8.AppendText(Environment.NewLine & "Canceled!")
    ElseIf e.Error IsNot Nothing Then
        TextBox8.AppendText(Environment.NewLine & "Error: " & e.Error.Message)
    Else
        TextBox8.AppendText(Environment.NewLine & "Done!")
    End If
End Sub

and, I use the following code to stop backgroundworker proccess ...


Code:

Private Sub Button55_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles Button55.Click
    If Me.UnpackSystem.IsBusy Then
        Me.UnpackSystem.CancelAsync()
    End If
    Dim cmd() As Process
    cmd = Process.GetProcessesByName("cmd")
    If cmd.Count > 0 Then
        Process.GetProcessesByName("cmd")(0).Kill()
    End If
End Sub

But it not be canceled, Where is my problem?

httpWebRequest.Timeout On value provided or on IIS?

$
0
0
Hello.

doing this:
httpWebRequest.Timeout = 30
requestStream ...etc

I need to know if the timeout is happening on the requested url by IIS or by the webrequest.

This is because I am trying to simulate a timeout on a web service but since i do not have access to that particular web service, I am trying by using a non existent post on google "https://www.google.com:81" . this will always give me a 60 seconds timeout, although I am modifying the httpWebRequest.Timeout value.
So my quest is that is is the IIS timeout that i erroring out and not the url site waiting.

Can someone confirm?
Also if this is the case, is there a Microsoft documentation for this somewhere? I need to log it in officially.

Thanks.

Need Help Converting time between two timezones.

$
0
0
Hi everyone,
First off i really apprecaite the time you are taking to help me.

im writing a simple (or so i thought) app for a work collegue
i want to convert a user defined time to Eastern Standard time. e.g

user inputs the hours and minutes of a time in 24 hour format.
this variable is then declared as either IST, PST or GMT

this value is then converted to EST and displayed by a label.

it will be used for reporting.
Im using a drop down box for differentiating between IST PST and GMT
I've been trying to figure my way around the convertime command but cant seem to work out what arguments it wants.
can you help.
i'll post what code I'm using (please be nice, I'm not claiming to be an expert and am willing to learn)
Code:

Dim timeinput as date
        Dim hour As Integer
        Dim minute As Integer
        Dim second As Integer
        hour = TextBox1.Text
        minute = TextBox2.Text
        second = 0
        timeinput = $"{hour}:{minute}:{second}"
        timeinput.ToOADate()
        Label1.Text = timeinput.ToString("HH:mm:ss")
        Dim istZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")
        Dim istTime As Date
        istTime = timeinput
        Label3.Text = istTime.ToString("HH:mm:ss")
        Dim estZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
        Dim estTime As DateTimeOffset = TimeZoneInfo.ConvertTime(istTime, estZone)
        IIf(estZone.IsDaylightSavingTime(estTime),
                      estZone.DaylightName, estZone.StandardName)
        Label2.Text = estTime.ToString("HH:mm:ss")

if there is an easier way please help me

VS 2010 Need help getting full file names

$
0
0
I need complete file names, but the code below only gets up to 24 characters. I'm not sure what's the problem. Just know it's not the buffer. I have to get this code to play nice since it's part of a larger program.

VB.NET 2010
Configuration Manager: x86

Code:

Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1

    Public Const LVM_FIRST As UInteger = &H1000
    Public Const LVM_GETITEMCOUNT As UInteger = LVM_FIRST + 4
    Public Const LVM_GETITEM = (LVM_FIRST + 5)
    Public Const LVM_GETITEMW As UInteger = LVM_FIRST + 75
    Public Const LVM_GETITEMPOSITION As UInteger = LVM_FIRST + 16
    Public Const LVM_GETITEMTEXT = (LVM_FIRST + 45)
    Public Const PROCESS_VM_OPERATION As UInteger = &H8
    Public Const PROCESS_VM_READ As UInteger = &H10
    Public Const PROCESS_VM_WRITE As UInteger = &H20
    Public Const MEM_COMMIT As UInteger = &H1000
    Public Const MEM_RELEASE As UInteger = &H8000
    Public Const MEM_RESERVE As UInteger = &H2000
    Public Const PAGE_READWRITE As UInteger = 4
    Public Const LVIF_TEXT As Integer = &H1

    <DllImport("kernel32.dll")> _
    Public Shared Function VirtualAllocEx(ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UInteger, ByVal flAllocationType As UInteger, ByVal flProtect As UInteger) As IntPtr
    End Function

    <DllImport("kernel32.dll")> _
    Public Shared Function VirtualFreeEx(ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UInteger, ByVal dwFreeType As UInteger) As Boolean
    End Function

    <DllImport("kernel32.dll")> _
    Public Shared Function CloseHandle(ByVal handle As IntPtr) As Boolean
    End Function

    <DllImport("kernel32.dll")> _
    Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As IntPtr, ByVal nSize As Integer, ByRef vNumberOfBytesRead As UInteger) As Boolean
    End Function

    <DllImport("kernel32.dll")> _
    Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As IntPtr, ByVal nSize As Integer, ByRef vNumberOfBytesRead As UInteger) As Boolean
    End Function

    <DllImport("kernel32.dll")> _
    Public Shared Function OpenProcess(ByVal dwDesiredAccess As UInteger, ByVal bInheritHandle As Boolean, ByVal dwProcessId As UInteger) As IntPtr
    End Function

    <DllImport("user32.DLL")> _
    Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function

    <DllImport("user32.DLL")> _
    Public Shared Function FindWindow(ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
    End Function

    <DllImport("user32.DLL")> _
    Public Shared Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, ByRef dwProcessId As UInteger) As UInteger
    End Function


    Public Structure LVITEM
        Public mask As Integer
        Public iItem As Integer
        Public iSubItem As Integer
        Public state As Integer
        Public stateMask As Integer
        Public placeholder1 As Integer
        Public pszText As Integer
        Public placeholder2 As Integer
        Public cchTextMax As Long
        Public iImage As Integer
    End Structure


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Size = New System.Drawing.Size(542, 622)

        Dim listview As New ListView
        With listview
            .Size = New System.Drawing.Size(500, 560)
            .Location = New System.Drawing.Point(13, 13)
            .View = View.Details
            .Font = New Font("Microsoft Sans Serif", 11)
            .Columns.Add("#", 20)
            .Columns.Add("Name", 150)
        End With
        Me.Controls.Add(listview)

        'Get the handle of the desktop listview
        Dim vHandle As IntPtr = FindWindow("Progman", "Program Manager")
        vHandle = FindWindowEx(vHandle, IntPtr.Zero, "SHELLDLL_DefView", Nothing)
        vHandle = FindWindowEx(vHandle, IntPtr.Zero, "SysListView32", "FolderView")

        'Get total count of the icons on the desktop
        Dim vItemCount As Integer = SendMessage(vHandle, LVM_GETITEMCOUNT, 0, 0)

        Dim itemIndex As Integer

        Dim vProcessId As UInteger
        GetWindowThreadProcessId(vHandle, vProcessId)
        Dim vProcess As IntPtr = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, vProcessId)
        Dim vPointer As IntPtr = VirtualAllocEx(vProcess, IntPtr.Zero, 255, MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE)

        Try
            For j As Integer = 0 To vItemCount - 1

                'Declare and populate the LVITEM structure.
                Dim vBuffer As Byte() = New Byte(255) {}
                Dim vItem As New LVITEM()
                vItem.iSubItem = 0
                vItem.cchTextMax = vBuffer.length
                vItem.pszText = vPointer.ToInt32
                vItem.mask = LVIF_TEXT
                vItem.iItem = itemIndex

                Dim ptrvItem As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(vItem))
                Marshal.StructureToPtr(vItem, ptrvItem, False)

                'Write the vItem structure into the desktops process memory
                Dim vNumberOfBytesRead As UInteger = 0
                WriteProcessMemory(vProcess, vPointer, ptrvItem, Marshal.SizeOf(vItem), vNumberOfBytesRead)

                'Get the item at itemIndex
                SendMessage(vHandle, LVM_GETITEMTEXT, j, vPointer.ToInt32())

                'Read item text from desktop process memory
                ReadProcessMemory(vProcess, vPointer, Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), 255, vNumberOfBytesRead)

                Dim itemText As String = Encoding.UTF7.GetString(vBuffer, 0, CInt(vNumberOfBytesRead))

                Dim lvi As New ListViewItem
                lvi.Text = CStr(j + 1)
                lvi.SubItems.Add(itemText)

                listview.Items.Add(lvi)
                listview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
            Next
        Finally
            VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE)
            CloseHandle(vProcess)
        End Try
    End Sub

End Class

VS 2008 [RESOLVED] Fitting a form into a smaller monitor

$
0
0
Hi , I recently faced a problem : I started a program of mine in a portable PC but I couldn't handle the buttons on a form because the form was not visible whole in the screen ! The monitor was too small for that form !
So I wonder if there is a way I can solve this problem without radically changing the lay out of the various controls on the form . I hope there is a control like a scroll bar so that I can see the rest of the form . If I remember well , back in VB6 there was such a control on which one could place all of his controls and if needed the user could move the scroll bars to access all parts of the form . I think it was called Picture box .
Anyway , the solution shouldn't be obligatorily some scroll bars . I only mentioned scroll bars because that's what crossed my mind .
In fact if there is a way to bypass this problem without even coding , then that's fine by me . Maybe a way to move around the form and see the rest of it ; just saying .

VS 2013 Restore executable file from database

$
0
0
I have stored an executable file as a byte array in an SQL Server database. I can restore the file successfully but when I launch it, I am getting this "This app can't run on your PC app" on Windows 10 Pro 64-bit.

https://snag.gy/bZXvRE.jpg

I am not getting this error when I save and restore files of other types (such as PDF, TXT, DOCX or XLSX) in the same way.

[RESOLVED] Move form and code from tabs into separate form

$
0
0
I created a form with a tab control. The tab control has 5 tabs with forms on each tab. I have decided to go in a different direction and would like to move the form and code from each tab into it's own form. I have looked all over on the internet for information how to do it. Can anyone help? Thanks

VS 2015 Add button to the titlebar??

$
0
0
Ok ... Now I have seen many examples of how to do this... but all of them seem to be somewhat "tacked on" to me.

Opera has a nice implementation of this as can be seen below:
Name:  Opera.png
Views: 91
Size:  1.7 KB
... and works well with OS themes too :)... and highlights correctly with the fading animation etc.

But I have not really seen anything else that comes close to this in programming ...

Even with rendering on the NC area... I still have the issue of how to "theme" the button ... as the built in renderer seems to use a "legacy" renderer (the one that is still used on MDI forms)...
as can be seen below:
VB.Net Code:
  1. Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  2.     Dim r As New VisualStyles.VisualStyleRenderer(VisualStyles.VisualStyleElement.Window.HelpButton.Normal)
  3.     r.DrawBackground(e.Graphics, New Rectangle(0, 0, 32, 32))
  4. End Sub
Name:  CrudRender.png
Views: 92
Size:  1.9 KB

...Any ideas or good examples on how to make this appear nice and be *somewhat* compatible?

Thanks in advance,
Kris
Attached Images
  

vb.net System.InvalidOperationException

$
0
0
hi dears
A little while ago suddenly, Software encountered an error
Of course, this problem occurred when I deleted the Windows tmp folder

this code exception detail error
Code:

System.InvalidOperationException was unhandled
  Message=An error occurred creating the form. See Exception.InnerException for details.  The error is: The system cannot find the file specified
  Source=Gsd Android Tool
  StackTrace:
      at Gsd_Android_Tool.My.MyProject.MyForms.Create__Instance__[T](T Instance) in :line 197
      at Gsd_Android_Tool.My.MyProject.MyForms.get_Home()
      at Gsd_Android_Tool.My.MyApplication.OnCreateMainForm() in D:\my devrloping\tools src\Gsd Android Tool\Gsd Android Tool\Gsd Android Tool\My Project\Application.Designer.vb:line 35
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
      at Gsd_Android_Tool.My.MyApplication.Main(String[] Args) in :line 81
      at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
      ErrorCode=-2147467259
      Message=The system cannot find the file specified
      NativeErrorCode=2
      Source=System
      StackTrace:
            at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
            at RegawMOD.Command.HandleOutput(Process p, AutoResetEvent outputWaitHandle, AutoResetEvent errorWaitHandle, Int32 timeout, Boolean forceRegular)
            at RegawMOD.Command.RunProcessReturnOutput(String executable, String arguments, Int32 timeout)
            at RegawMOD.Android.Fastboot.ExecuteFastbootCommand(FastbootCommand command)
            at Gsd_Android_Tool.Home..ctor() in D:\my devrloping\tools src\Gsd Android Tool\Gsd Android Tool\Gsd Android Tool\Form1.vb:line 15
      InnerException:

How can I fix this problem?

VB.NET GetObject and save makes spreadhsheet unreadable in Excel

$
0
0
I write to a spreadhsheet and can go back into VB.NET and read it again without any issues. I can also read spreadsheet in open Office without any issues, but in OO I can't save in XLSX or I'd just be ok with this weird step. But I cannot open up spreadsheet in Excel. It just says book on top and there is not an option to save and no data is present.

Any Ideas?

VS 2010 How to group and rank with reference to another column

$
0
0
Hello gurus
I need help in grouping or partitioning and ranking according to the subject. Every subject must have 1st to last student.
Am using the codes below with vb 2010


Dim TotaledRecords = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text
Select p
Order By p.Total Descending

For j = 1 To TotaledRecords.Count
TotaledRecords.ToList(j - 1).Position = j
Next
db.SubmitChanges()

I want it to restart the ranking with respect to the subject
thank you
See attached picture
Name:  help to code.jpg
Views: 23
Size:  36.0 KB
Attached Images
 

[VB.NET] Print selected datagridview row into individual pages with front and back

$
0
0
Hi,now I'm trying to print a datagridview cell data (NOT the whole datagridview) into individual page (ID card badge actually),according to individual rows,the new requirement here is certain data is print at FRONT,while certain data is print at BACK.

Google gave me some examples which work ONLY at one print event only.Mean each time only one FRONT and BACK of card are printed,then have to re run the whole process again.

For my understanding,it's related to Duplex printing and need to workaround the PageNumber and also HasMorePages,but I have no clue where to insert the related codes.

Here is my sample codes,which work well on FRONT pages printing:

Private rowsToPrint As Queue(Of DataGridViewRow)

Private Sub PrintDocument1_BeginPrint(sender As Object, e As PrintEventArgs) Handles PrintDocument1.BeginPrint
Dim sr = DataGridView1.SelectedRows
If sr.Count = 0 Then
e.Cancel = True
Else
rowsToPrint = New Queue(Of DataGridViewRow)(sr.Cast(Of DataGridViewRow)())
End If
End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim rtp = rowsToPrint.Dequeue()
Dim s2 As String = rtp.Cells(2).Value.ToString
Dim f2 As New Font("Arial", 10)
Dim s4 As String = rtp.Cells(4).Value.ToString
Dim f4 As New Font("Arial", 10)
e.Graphics.DrawString(s2, f2, Brushes.Black, 10, 10)
e.Graphics.DrawString(s4, f4, Brushes.Black, 30, 30)
e.HasMorePages = rowsToPrint.Any()
End Sub
Attached Images
 

How can I get MIME into texstring

$
0
0
HI,
I want to send a picture to a webbrowser and created the server in VB, which works well.
To get the required MIME format of the picture I loaded it as attachment, sent it to myself opened the Email in a texteditor, copied the MIME part of the picture and sent it with the server. This works so far.
Now, I would like to extract the MIME textstring directly from the attachment and tried this:
Code:

   
        Dim filename As String = "D:\2034230.JPG"
        Dim data As Attachment = New Attachment(filename)
        Dim content As ContentType = data.ContentType
        content.MediaType = MediaTypeNames.Image.Jpeg
        Dim MimeStream As Stream = data.ContentStream

Could someboy help me how to get the stream into a string which hopefully holds the expected picture in MIME format?
thanks,

VB.net Code to do an MQGET and MQPUT by MessageID

$
0
0
I'm trying to use VB.net to GET a message from MQ, (save the MessageId) then put a message to MQ with the same MESSAGE ID using VB.net. The problem I'm getting is after I do the MQGET, I try to save the Message ID to a string, then when I do the MQPUT and specify the same Message ID, the program just bombs. It doesn't like something with how I store the Message id.

I get the message and do the following which seems to work.
Save_md = System.Text.Encoding.UTF8.GetString(mqMsg.MessageId) <= saves the message id from the get to variable save_md.

Now I later try to put messages with that message id in Save_md. Here is the code.
mqMsg.MessageId = System.Text.Encoding.UTF8.GetBytes(Save_md)

Once it hits this line, it just bombs the program. So I'm guessing it is something with the conversion from BYTES to text and back and forth. I've looked around for better ways to do it, but I can't seem to find it for vb.net.

Does anyone have any ideas?
Thanks,
Gary

Designerless Form Creation

$
0
0
For the last few weeks I have been hammering out InfoPath forms and workflows. Basically I have been living and breating all things SharePoint:sick:

InfoPath "Code-Behind" can be unforgiving, as you would expect from working with any XML nested nightmares...

Recently I have decided to get clever and leverage some controls out of the .Forms namespace...

It's a bit hit and miss but I am working things out.

Right now I am wondering why my loop in the below code wouldn't be working, I am not sure if I am initializing the controls adequately, or if maybe I should try adding the routine to an event rather than initialization.

Also It could be fun to get a discussion going on how you would go about rendering a form if you did not have the designer and were forced to do it all in code. - I've also been wondering if maybe I could design the form in VS then copy and somehow reuse the "Form.Designer.vb"

Anyway, the problem loop is commented with "not running" below.

Code:

        Public Sub CTRL38_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
            Dim MachineForm As New Form
            Dim HeaderPanel As New Panel With {.Padding = New Padding(10)}
            Dim BodyPanel As New Panel With {.Padding = New Padding(10)}
            Dim FooterPanel As New Panel With {.Padding = New Padding(10)}
            Dim DGV_Machine As New DataGridView With {.DataSource = DSet.Tables("Machines")}

            With DGV_Machine
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
                .Dock = DockStyle.Fill
         
            End With

            With HeaderPanel
                .Dock = DockStyle.Top
            End With

            With BodyPanel
                .Dock = DockStyle.Fill
                .Controls.Add(DGV_Machine)
                .BringToFront()
            End With

            With FooterPanel
                .Dock = DockStyle.Bottom
            End With

            With MachineForm
                .Controls.Add(FooterPanel)
                .Controls.SetChildIndex(FooterPanel, 2)

                .Controls.Add(HeaderPanel)
                .Controls.SetChildIndex(HeaderPanel, 1)

                .Controls.Add(BodyPanel)
                .Controls.SetChildIndex(BodyPanel, 0)

                Dim ColsWidth As Integer = Nothing
                For Each Col As DataGridViewColumn In DGV_Machine.Columns 'not running
                    ColsWidth += Col.Width
                    MessageBox.Show(ColsWidth)
                Next
                .Width = ColsWidth
                .Height = Screen.PrimaryScreen.Bounds.Height - 25

                .StartPosition = FormStartPosition.Manual
                .Location = New Drawing.Point(25)

                .ShowDialog()
            End With
        End Sub


DGV usage

$
0
0
I would like to use a DGV to display data from two tables. The first table has one of the fields I am interested in and is the parent table for a second table (child) that has the other two fields I am interested in. The first table has a primary key that is related to the child table with a foreign key. Can this be done and, if so, how?

[RESOLVED] Designerless Form Creation

$
0
0
For the last few weeks I have been hammering out InfoPath forms and workflows. Basically I have been living and breating all things SharePoint:sick:

InfoPath "Code-Behind" can be unforgiving, as you would expect from working with any XML nested nightmares...

Recently I have decided to get clever and leverage some controls out of the .Forms namespace...

It's a bit hit and miss but I am working things out.

Right now I am wondering why my loop in the below code wouldn't be working, I am not sure if I am initializing the controls adequately, or if maybe I should try adding the routine to an event rather than initialization.

Also It could be fun to get a discussion going on how you would go about rendering a form if you did not have the designer and were forced to do it all in code. - I've also been wondering if maybe I could design the form in VS then copy and somehow reuse the "Form.Designer.vb"

Anyway, the problem loop is commented with "not running" below.

Code:

        Public Sub CTRL38_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
            Dim MachineForm As New Form
            Dim HeaderPanel As New Panel With {.Padding = New Padding(10)}
            Dim BodyPanel As New Panel With {.Padding = New Padding(10)}
            Dim FooterPanel As New Panel With {.Padding = New Padding(10)}
            Dim DGV_Machine As New DataGridView With {.DataSource = DSet.Tables("Machines")}

            With DGV_Machine
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
                .Dock = DockStyle.Fill
         
            End With

            With HeaderPanel
                .Dock = DockStyle.Top
            End With

            With BodyPanel
                .Dock = DockStyle.Fill
                .Controls.Add(DGV_Machine)
                .BringToFront()
            End With

            With FooterPanel
                .Dock = DockStyle.Bottom
            End With

            With MachineForm
                .Controls.Add(FooterPanel)
                .Controls.SetChildIndex(FooterPanel, 2)

                .Controls.Add(HeaderPanel)
                .Controls.SetChildIndex(HeaderPanel, 1)

                .Controls.Add(BodyPanel)
                .Controls.SetChildIndex(BodyPanel, 0)

                Dim ColsWidth As Integer = Nothing
                For Each Col As DataGridViewColumn In DGV_Machine.Columns 'not running
                    ColsWidth += Col.Width
                    MessageBox.Show(ColsWidth)
                Next
                .Width = ColsWidth
                .Height = Screen.PrimaryScreen.Bounds.Height - 25

                .StartPosition = FormStartPosition.Manual
                .Location = New Drawing.Point(25)

                .ShowDialog()
            End With
        End Sub

[RESOLVED] DGV usage

$
0
0
I would like to use a DGV to display data from two tables. The first table has one of the fields I am interested in and is the parent table for a second table (child) that has the other two fields I am interested in. The first table has a primary key that is related to the child table with a foreign key. Can this be done and, if so, how?

How can I format datagridview to view data from mysql database

$
0
0
how can I make this....

Name:  Capture1.PNG
Views: 76
Size:  6.7 KB

to view like this?

Name:  Capture.PNG
Views: 65
Size:  3.9 KB

Can you help me with this?


Cheers,
Attached Images
  

Is the re an easy way to pluck out the set of digits from a textbox entry?

$
0
0
Two sets of data in a line are separated using a "-" as follows: XXXX - ###, or XXXXXX - ##, or even XX - ###
The number of digits at the end can change from 1 to 4. The hyphen is a separator.

Is there a single line of code that will see the hyphen then pull out the rest of the line to the right of the hyphen?

I am considering reading the number of digits in the phrase, counting to the hyphen, subtract the two then grab that number of digits after the hyphen. Too many lines of code.

Is there a singe command to do this?
Viewing all 27289 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>