TnTinMN 418 Practically a Master Poster

Is there a vb.net programming qustion in here that I'm missing?

Click Here

TnTinMN 418 Practically a Master Poster

Your code should execute if your change

myCommand = New OleDbCommand("SELECT * FROM tbleMember WHERE FormNo='" & cmbName.SelectedValue.toString & "'", MyConn)

to

myCommand = New OleDbCommand("SELECT * FROM tbleMember WHERE FormNo=" & cmbName.SelectedValue.toString , MyConn)

Unless you intend to extract more values than are shown in the SelectedIndexChanged handler, I would suggest that you rethink this code a bit. There is no need for this additional query as you have the valu you are trying to retrieve.

Also, I would also suggest that you change:

Dim asql As String = ("SELECT LastName +', '+ FirstName +'   '+ MiddleName AS FullName,FormNo FROM tbleMember")

to

Dim asql As String = ("SELECT LastName +', '+ FirstName + IIF(MiddleName is Null,'',' ' + MiddleName) AS FullName,FormNo FROM tbleMember")

This will prevent a blank entry in the combobox if there is no MiddleName.

TnTinMN 418 Practically a Master Poster

To retrieve the value there must be a pattern that can be implemented, let us assume that the pattern is as follows.

  1. There is only one table row with where the first child element has it's innner text equal to "In Process".
  2. The "In Process" element has at least one sibling and it can be parsed as a number.

Essentially, for this to work reliably, the HTML must be layedout like you have shown. Using these constraints, it is possible to construct a query of the document to attempt to retrieve a number. Additional constrainst could be imposed, but I'll leave that to you.

The following code demonstrates how to query a webbrowser's document and attempt to return a number based on the constraints defined above.

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

     Dim value As Single
     If GetMyValue(wb1, value) Then
        MsgBox("the value is: " & value.ToString)
     Else
        MsgBox("could not retrieve value")
     End If


  End Sub

  Private Function GetMyValue(ByVal wb As WebBrowser, ByRef value As Single) As Boolean
     If wb.Document Is Nothing Then Return False 'no point in going any further

     Dim rows As List(Of HtmlElement) = (From tr In wb.Document.GetElementsByTagName("TR") Select tr Where CType(tr, HtmlElement).FirstChild.InnerText = "In Process").Cast(Of HtmlElement).ToList
     If rows.Count = 1 Then
        Dim firstElementAfterInProcess As HtmlElement = rows(0).FirstChild.NextSibling

        If firstElementAfterInProcess IsNot Nothing Then
           Try
              value = Single.Parse(firstElementAfterInProcess.InnerText)
              Return True
           Catch ex As Exception
              'could not parse a value
              Return False
           End Try
        Else
           Return False

        End If 'firstElementAfterInProcess IsNot …
TnTinMN 418 Practically a Master Poster

This does not answer the question you posted, but it does what you said you wanted to accomplish; kill the java process currently running under the browser control.

Imports System.Runtime.InteropServices

Public Class Form1

   Private Sub btnKillJava_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKillJava.Click
      KillJavaForBrowser(WebBrowser1)
   End Sub

   Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
      BrowserRefresh(WebBrowser1)
   End Sub

   Private Sub KillJavaForBrowser(ByVal browser As WebBrowser)
      ' get a list of the browser's child windows
      Dim childHandles As List(Of IntPtr) = NativeMethods.GetChildWindows(browser.Handle)

      ' make a list of PID's associated with these child window handles

      Dim childPIDs As New List(Of IntPtr)
      Dim pid As IntPtr

      For Each h As IntPtr In childHandles
         pid = IntPtr.Zero
         NativeMethods.GetWindowThreadProcessId(h, pid)
         childPIDs.Add(pid)
      Next h

      ' loop through the unique child window PID's searching for java.exe

      For Each pid In childPIDs.Select(Function(id As IntPtr) id).Distinct.ToList
         Dim p As Process = Process.GetProcessById(pid.ToInt32)
         If p.MainModule.ModuleName.ToLower = "java.exe" Then
            ' found it, so kill it and stop loop
            p.Kill()
            Exit For
         End If
      Next pid
   End Sub

   Private Sub BrowserRefresh(ByVal browser As WebBrowser)
      browser.Navigate(browser.Url)
   End Sub
End Class


Public Class NativeMethods
   <DllImport("User32.dll")> _
   Private Shared Function EnumChildWindows _
     (ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, _
     ByVal lParam As IntPtr) As Boolean
   End Function

   Public Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean

   Public Shared Function GetChildWindows(ByVal ParentHandle As IntPtr) As List(Of IntPtr)
      Dim ChildrenList As New List(Of IntPtr)
      Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)
      Try
         EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle))
      Finally …
renzlo commented: thanks +2
TnTinMN 418 Practically a Master Poster

I'm sure your professors would find this to be an interesting topic:

"How I am earning a degree in computer programming without ever having to learn the material via the use of internet help forums"

Reverend Jim commented: Sounds like a real winner +12
TnTinMN 418 Practically a Master Poster

I do not kown if it is possible to force a silent browser download, but .Net provides many ways to download files if you know the source address.

Two simple ones to use:

My.Computer.Network.DownloadFile Method

WebClient.DownloadFile Method

TnTinMN 418 Practically a Master Poster

.Net does not support true transparency. Transparency is mimicked by copying the foreground of the parent control to the background of the "transparent" control. That stated, the best that you can do is to try and mitigate the problems. You are on the right track by invalidating the panel to force a redraw of the background. There are a few things that can help the flickering, but it will still be there. The slower your computer's graphics, the worse the flickering will be.

Here is a custom Panel control that I've found to give acceptable results.

Public Class TransPanel
   Inherits Panel
   Public Sub New()
      BackColor = Color.Transparent
      AutoScroll = True
      ' setting these 2 styles has a big positive effect
      SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
      SetStyle(ControlStyles.AllPaintingInWmPaint, True)
   End Sub

   Protected Overrides Sub OnScroll(ByVal se As System.Windows.Forms.ScrollEventArgs)
      MyBase.OnScroll(se)
      Refresh()
   End Sub

   Protected Overrides Sub OnMouseWheel(ByVal e As System.Windows.Forms.MouseEventArgs)
      MyBase.OnMouseWheel(e)
      Refresh()
   End Sub

End Class
TnTinMN 418 Practically a Master Poster

How can I draw the selected text to the combobox?

Take a look at this project: http://www.codeproject.com/Articles/10670/Image-ComboBox-Control

There is a lot of good stuff in it on how to manipulate the edit box part of the combobox.

TnTinMN 418 Practically a Master Poster

I suspect your problem is that the splitcontainer only captures the mouse when you move over the splitterbar. Try wiring up the mouse move event for each panel in the container like this:

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     AddHandler SplitContainer1.Panel1.MouseMove, AddressOf SplitContainer1_MouseMove
     AddHandler SplitContainer1.Panel2.MouseMove, AddressOf SplitContainer1_MouseMove
  End Sub

  Private Sub SplitContainer1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SplitContainer1.MouseMove
     Debug.WriteLine(MousePosition.ToString)
  End Sub
TnTinMN 418 Practically a Master Poster

Assuming that you are using VB's "application framework" you have a couple of options. To ensure that the framework is enabled, go to the "Solution Explorer" and either double-left click on "My Project" or right-click on it and select open.
Open_Props

This will open the project's property setting page.

props_page

Make sure that the "Enable application framework is checked". No notice the "Shutdown mode" combobox. In this case it is set to "When startup form closes". This means exactly as is implied, the application shutsdown when the startup form is closed.

Now assuming that you are using the "Application.Exit" method (not the "End" statement) to exit the application either via clicking your close program button or in the "FormClosing" event handler, you can put your logout code in just the "Startup Form's closing event handler. No need to put this logic in all of the forms. By using "Application.Exit" versus "End", you allow all message loops to complete first. The "End" statement does very little cleanup and like slamming the door closed on the application.

Another option would be to using the application's "Shutdown" event handler. You access the code page for this event by clicking on the "View Application Events" button shown in the above picture.

app_events_1

shutdown_event

coded_shutdown
Now you add you logout code under the shutdown event. The "My" namespace is meant to be your extentable …

Reverend Jim commented: Excellent advice +12
john.knapp commented: excellent, should be a tutorial +3
TnTinMN 418 Practically a Master Poster

Are you sure that tableElem has a value and is not nothing?

The DocumentCompleted event can fire many times when loading an url, I've found this technique very useful to make sure that the document is the one I want. Try this in the DecomentCompleted handler.

  If webBrowserX.Url = e.Url Then
     Dim tableElem As HtmlElement = webBrowserX.Document.GetElementById("count-in")
     If tableElem IsNot Nothing Then
        TextBox1.Text = TextBox1.Text & tableElem.InnerText

     Else
        Stop ' this is only for debugging

     End If
  End If
TnTinMN 418 Practically a Master Poster

program that contains a Rich Text Box & a scroll bar where scroll bar represents the size of font size of selected text in Rich Text Box as soon as user scrolls the scroll bar.help????

Do you have two separate controls ( a RichTextBox and a Vertical Scrollbar)?

If this is the case then, you could something like this in the RTB's scroll event handler.

  Private Sub RichTextBox1_VScroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.VScroll
     VScrollBar1.Size = New Size(VScrollBar1.Width, RichTextBox1.SelectionFont.Height)
  End Sub

Or do you mean that you want to control the size of the RTB's vertical scrollbar thumb? That can be done as well but is a bit more involved. Here is a custom RTB control that acomplishes setting the thumb size when the RTB receieves a VScroll message.

   Public Class RTBwithThumbHeight
         Inherits RichTextBox

         Private Const WM_VSCROLL As Int32 = &H115

         Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            MyBase.WndProc(m) ' Process a normal


            If m.Msg = WM_VSCROLL Then
               ' get the size of the scrollbar.  Probably could just use the client window height instead
               Dim sbi As New SCROLLBARINFO
               sbi.cbSize = Marshal.SizeOf(sbi)
               Dim res As Boolean = GetScrollBarInfo(Me.Handle, OBJID.OBJID_VSCROLL, sbi)

               ' get the scroll bar scale values
               Dim si As New SCROLLINFO
               si.cbSize = CUInt(Marshal.SizeOf(si))
               si.fMask = ScrollInfoMask.SIF_ALL 'retrieve all values
               GetScrollInfo(Me.Handle, SBOrientation.SB_VERT, si)

               ' compute font line height scaled to scroll bar dimensions
               Dim scaleFactor As Double = (si.nMax - si.nMin) / ((sbi.rcScrollBar.bottom - sbi.rcScrollBar.top) - (2% * SystemInformation.VerticalScrollBarArrowHeight)) …
TnTinMN 418 Practically a Master Poster

Textboxes use only the LF character. This is one way to handle it.

  Dim lines() As String = RichTextBox1.Lines
  'initialize stringbuilder to textlength + num lines  (this adds space for VbCr)
  Dim sb As New System.Text.StringBuilder(RichTextBox1.TextLength + lines.Length + 20)
  For Each l As String In lines
     sb.AppendLine(l) 'add line with CrLF appended
  Next
  Dim EmailMessage As String = sb.ToString
TnTinMN 418 Practically a Master Poster

I can't believe there is nothing about this in my textbook for this chapter. I'm getting ripped off

Perhaps. But maybe the intent of the lesson was to teach you the value of a function to perform a common task. You had previously demonstrated that you had thought out the necessary steps to write your own function. If your teacher is any good, I bet that he/she would be more impressed by a function that your developed on your own than by using a pre-written one.

TnTinMN 418 Practically a Master Poster

Add a property to "infoEntry" to accept a reference to the ListView.

    private ListView _lv;
    public ListView lv
    {
        get { return _lv; }
        set { _lv = value; }
    }

Then set that property before showing "dataWindow"

dataWindow.lv = this.toSend;
dataWindow.ShowDialog();

Then: lv.Items.Add("test").SubItems.AddRange(row1);

TnTinMN 418 Practically a Master Poster
TnTinMN 418 Practically a Master Poster
TnTinMN 418 Practically a Master Poster

Assuming you have read the files into some string variables, you could do something like this:

       Dim AnswerKey() As Char = "TTFFTT".ToCharArray
  Dim StudentAnswers() As Char = "T-FFFT".ToCharArray

  Dim NumCorrect As Int32 = StudentAnswers.Where(Function(ans As Char, index As Int32) ans = AnswerKey(index)).Count
  Dim NumSkipped As Int32 = StudentAnswers.Where(Function(ans As Char, index As Int32) ans = "-").Count
  Dim NumIncorrect As Int32 = StudentAnswers.Length - NumCorrect - NumSkipped

  Dim score As Int32 = (NumCorrect * 4%) - NumIncorrect
TnTinMN 418 Practically a Master Poster

Ray,

I decided to put together a sample application to show how I would do the SendKeys method. I do not recommend using SendKeys as it is has to many dependencies to work properly and is too easily messed up by other processes.

This example also shows another method using Window's messages to send and retrieve text from another process. This is much easier to control and is more reliable.

I used Notepad as the external application.

This was developed in VS2008, so when you open "Countdown.vbproj", you may have to go through an upgrade process.

TnTinMN 418 Practically a Master Poster

Very confusing nomenclature! A form named timer1.

What is on the form "timer1" other than a timer that closes it?
Does the user interact with "timer1" while the creating form is executing the sendkeys code?

SendKeys simulates keyboard input by placing the requested keys into the keyboard input stream. The keyboard input stream is processed by the window that has input focus.

Is this chatbox on your form, an external application, or on a webpage in a webbrowser control? In any case, it needs to have focus for it to receive the keys sent.

TnTinMN 418 Practically a Master Poster

Hi staticclass,

And welcome to the irritating world of trying to use transparency in WinForms!

This may seem counter-intuitive, but instead of using the PictureBox Control, try using a Panel instead.

Place your image as the BackgroundImage. Use the BackgroundImageLayout property as you would the PictureBox SizeMode Property.

This will give you the ability to place labels using the Transparent BackColor as well as other panels with Transparent BackColor and get the transparent effect.

The only thing that you loose using this method is the ability to use animated Gifs. You can still use them as a picture, but they will not animate.

This will not be a perfect solution, as controls do not support true transparency. It is simulated by the controls parent drwing the background. You will see the inconsistancy when two of you png images or labels overlap.

TnTinMN 418 Practically a Master Poster

I am not aware of any issues in setting this property. I suspect that any issues you had in Excel VBA may have involved a registry value getting changed when you set a property, but that's just a guess. I normally enable script error suppression at the design level.

As these are errors are typically generated by bad java script code, thus supressing them should not be an issue. However, this little tidbit from MS makes me wonder.

When ScriptErrorsSuppressed is set to true, the WebBrowser control hides all its dialog boxes that originate from the underlying ActiveX control, not just script errors. Occasionally you might need to suppress script errors while displaying dialog boxes such as those used for browser security settings and user login. In this case, set ScriptErrorsSuppressed to false and suppress script errors in a handler for the HtmlWindow.Error event. For more information, see the code example in this topic.

See this for more info.

I also get browser errors regarding javascript and I don’t know how to handle that within the confines of VB.NET’s WebBrowser. As it is, I have to manually stop it from running or don’t, it doesn’t matter with regards to the query but it does stop my code at the DocumentCompleted event.

I don't know if you are aware of this or not, but when navigating to a given Url, you will likely get multiple "DocumentCompleted" events fired. The way to handle this is:

  Private …
Stuugie commented: Thank you very much +2
TnTinMN 418 Practically a Master Poster

I do not use WPF much, but I believe the "IsHitTestVisible" property is the one that you want to set to false and not the "IsEnabled" property.

TnTinMN 418 Practically a Master Poster
   Sub SetVisibility()
      Dim i As Int32 = 1
      CType(Me.FindName("Button_" & i.ToString), Control).Visibility = Windows.Visibility.Hidden
   End Sub
TnTinMN 418 Practically a Master Poster

This may help with the script errors issue. Set the "ScriptErrorsSuppressed" property on the WebBrowser control to True. That will prevent the error dialog from opening.

TnTinMN 418 Practically a Master Poster

If I understand correctly, you want a similar effect to that seen in dragging a control from the ToolBox to the the Form in the Visual Studio Designer, but in your case from a button to PictureBox1.

This is probably going to confuse you, but the way I would handle this is to create an application message filter to track the mousemove and LeftMouseUp messages and raise my own events for these. This allows you to move everything to the Form level. "pBox" is initially added to the form and dragged around by the mouse. On releasing the LeftMouseButton, an event is raised. The event handler for this event does a hit test of pBox's rectangle with the client rectangle of PictureBox1. If any point of pBox is in the PictureBox1's client rectangle, pBox is added. If not it is discarded. I gave you an alternate If conditon that you can swap with the one used if you only want to add pBox if the TopLeft corner is in PictureBox1's client rectangle.

  Public Class Form1

     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If pBoxFilter IsNot Nothing Then
           Application.RemoveMessageFilter(pBoxFilter)
           pBoxFilter = Nothing
        End If
     End Sub

     Private TrackedPB As PictureBox

     Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
        pBoxSetup(My.Resources.SomeImage1, e)
     End Sub

     Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
        pBoxSetup(My.Resources.SomeImage2, e)
     End Sub

     Private WithEvents pBoxFilter As PBDragNDropFilter
     Private Sub pBoxSetup(ByVal ImageToPlace As Image, ByVal …
TnTinMN 418 Practically a Master Poster

or, try this.

nmaillet commented: Ha ha, haven't seen that one yet. +6
TnTinMN 418 Practically a Master Poster

here is a pattern you can try.

  Dim dt As New DataTable
  With dt
     .Columns.Add("c1", GetType(String))
     .Columns.Add("c2", GetType(String))
     .Rows.Add(New Object() {"hi", "fred"})
     .Rows.Add(New Object() {"hi", "barney"})
  End With
  Dim SelectionField As String = "c2"
  Dim res() As DataRow = dt.Select("[" & SelectionField & "]='" & TextBox1.Text.Trim & "'")
  If res.Length = 0 Then
     'not found
  Else
     'do something
  End If
TnTinMN 418 Practically a Master Poster

I'm not sure about how you select the image to place in "pBox", but I think this will give you the effect you are seeking.

  Private TrackedPB As PictureBox
  Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles PictureBox1.MouseDown

     If e.Button = Windows.Forms.MouseButtons.Left Then
        ' Left Button Down

        ' Using this function allows you to drag over existing
        ' PictureBoxes added to PictureBox1

        Dim loc As Point = PictureBox1Coord(sender, e)

        ' set the image however you want
        Dim pBox As New PictureBox With {.Image = My.Resources.SomeImage, _
                                         .Location = loc, _
                                         .Size = New Size(64, 64), _
                                         .BorderStyle = BorderStyle.FixedSingle, _
                                         .SizeMode = PictureBoxSizeMode.Zoom, _
                                         .Parent = PictureBox1 _
                                        }
        TrackedPB = pBox
        TrackedPB.BringToFront() 'Make sure this new PB is on top
        ' Need to wire-up the MouseDown and MouseMove Events for the 
        ' added PB to allow drag over and click
        AddHandler TrackedPB.MouseDown, AddressOf PictureBox1_MouseDown
        AddHandler TrackedPB.MouseMove, AddressOf PictureBox1_MouseMove
     End If
  End Sub

  Private Function PictureBox1Coord(ByVal sender As Object, ByVal e As MouseEventArgs) As Point
     If CType(sender, PictureBox).Equals(PictureBox1) Then
        Return e.Location
     Else
        Return PictureBox1.PointToClient(CType(sender, PictureBox).PointToScreen(e.Location))
     End If
  End Function

  Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
     If TrackedPB IsNot Nothing AndAlso e.Button = Windows.Forms.MouseButtons.Left Then
        TrackedPB.Location = PictureBox1Coord(sender, e)
     Else
        TrackedPB = Nothing
     End If
  End Sub
TnTinMN 418 Practically a Master Poster

Try changing: MainForm.WebBrowser1.DataBindings.Add("Url", ds.Tables("item"), "link")

To: MainForm.WebBrowser1.DataBindings.Add("Url", ds.Tables("item"), "link", True)

This enables formatting of the value which invokes the property's TypeConverter.

TnTinMN 418 Practically a Master Poster

I realize you have marked this thread solved, but you do realize that your example is a valid date don't you? 2012 is a leap year, hence IsDate(" February 29, 2012") will return true.

IsDate("February 30, 2012") would return false.

TnTinMN 418 Practically a Master Poster

Me bad. That should be Inherits not Implements.

TnTinMN 418 Practically a Master Poster
Public Class ControlDirtyTrackerCollection
Implements List(Of ControlDirtyTracker)


End Class
TnTinMN 418 Practically a Master Poster

Lines 40 and 41 of your OP.

Dim intNrStations As Integer 'Total number of station
ReDim arrMicrosensor(intNrStations)

The array "arrMicrosensor" has a length of 1 after these statements execute as "intNrStations" will have an initial value of zero. "ReDim arrMicrosensor(intNrStations)" is equivalent to: ReDim arrMicrosensor(0 To 0); therefore, any array index reference greater than zero will cause an out of bounds error.

Also remember that in Vb.Net arrays use zero based indexing.

TnTinMN 418 Practically a Master Poster

It just occured to me that if the room number does not have a letter component that the comparer will fail for two equal room numbers. Here is a corrected version.

Friend Class PatientRoomComparer
     Implements IComparer(Of Patient)

     Public Function Compare(ByVal x As Patient, ByVal y As Patient) As Integer Implements System.Collections.Generic.IComparer(Of Patient).Compare
        ' For Ascending Order
        ' x < y : return -1;  x = y : return 0; x > y : return 1

        Dim xparts(), yparts() As String
        Dim splitter() As Char = {" "c}

        xparts = x.Room.Split(splitter, System.StringSplitOptions.RemoveEmptyEntries)
        yparts = y.Room.Split(splitter, System.StringSplitOptions.RemoveEmptyEntries)

        If xparts.Length = 0 OrElse yparts.Length = 0 Then
           Throw New ArgumentException("Invalid Room Number")
        End If

        Dim xnum, ynum As Int32
        Int32.TryParse(xparts(0), xnum)
        Int32.TryParse(yparts(0), ynum)

        ' 1st compare the number part
        Dim returnvalue As Int32 = xnum.CompareTo(ynum)

        If returnvalue = 0 Then ' numbers are equal, compare letters
           If xparts.Length = 1 AndAlso yparts.Length = 1 Then
             ' no letter component for x : x < y
             Return 0
           End If

           If xparts.Length = 1 Then
             ' no letter component for x : x <y
             Return -1

           End If
           If yparts.Length = 1 Then
             ' no letter component for y : x >y
             Return 1
           End If

           ' If this point is reached, compare the letters
           Return xparts(1).CompareTo(yparts(1))

        Else

           Return returnvalue

        End If
        Debug.WriteLine(Compare.ToString)
     End Function
  End Class
TnTinMN 418 Practically a Master Poster

Possibly this is what you mean?

        Int32 i = 255;
        char c = (char)i;
        // or 
        string s = new string(c,1);
TnTinMN 418 Practically a Master Poster

Set the Series2.YAxisType to Secondary

            With .Series("Series2")
                .ChartArea = "Fred"
                .ChartType = SeriesChartType.Point
                .XValueType = ChartValueType.String
                .XValueMember = "Linename"
                .YValueType = ChartValueType.DateTime
                .YValueMembers = "Count"
                .YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary
                End With
TnTinMN 418 Practically a Master Poster

I'm freehanding these modifications to add the count field, but I sure that you will let me know if it throws an error. ;)

  Select DTRow(grpDT, _
           New Object() {LINENAME, _
                         New TimeSpan(CType( _
                                            grp.Average(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks),  _
                                             Int64 _
                                             ) _
                                       ), _
                          grp.Count() _
                        } _
          )

Now you need to make room for the count in the datatable.

        Dim grpDT As DataTable = Ds.Tables(0).Clone 'Copy structure of original Table
        'Make the changes you indicated to the Table structure.  You can do this as long as the table is empty.
        grpDT.Columns("EVENTTM").DataType = GetType(TimeSpan)
        grpDT.Columns("EVENTTM").ColumnName = "DURATION"

' ********  Column to hold Count        
        grpDT.Columns.Add("Count", gettype(Int32))

As far as examples of LINQ go, there are a lot of them out there.

Just search:

  • MSDN LINQ VB 101 Examples
  • MSDN IEnumerable LINQ extensions
  • MSDN IEnumerable

Unfortunately, MS created an abomination called the anonymous type in some perverted effort to make writing LINQ queries simpler. If you read some of their BS, they will claim that you have to use the Anonymous type to hold the result. This is total misinformation and they can not even keep their own ranks in line as many of them write LINQ examples, as I have shown you, using a strongly typed target variable. This is a somewhat of a style preference, but to use the anonymous type you have to have Option Infer On, and this goes against my personal philosphy. I believe code should explicitly …

TnTinMN 418 Practically a Master Poster

Assuming all room numbers follow the pattern, [Number][Space][Letter], adding this class to your project this should do the trick.

  Friend Class PatientRoomComparer
     Implements IComparer(Of Patient)

     Public Function Compare(ByVal x As Patient, ByVal y As Patient) As Integer Implements System.Collections.Generic.IComparer(Of Patient).Compare
        ' For Ascending Order
        ' x < y : return -1;  x = y : return 0; x > y : return 1

        Dim xparts(), yparts() As String
        Dim splitter() As Char = {" "c}

        xparts = x.Room.Split(splitter, System.StringSplitOptions.RemoveEmptyEntries)
        yparts = y.Room.Split(splitter, System.StringSplitOptions.RemoveEmptyEntries)

        If xparts.Length = 0 OrElse yparts.Length = 0 Then
           Throw New ArgumentException("Invalid Room Number")
        End If

        Dim xnum, ynum As Int32
        Int32.TryParse(xparts(0), xnum)
        Int32.TryParse(yparts(0), ynum)

        ' 1st compare the number part
        Dim returnvalue As Int32 = xnum.CompareTo(ynum)

        If returnvalue = 0 Then ' numbers are equal, compare letters
           If xparts.Length = 1 Then
             ' no letter component for x : x <= y
             ' for sorting purposes can treat as <
             Return -1

           End If
           If yparts.Length = 1 Then
             ' no letter component for y : x >=y
             ' for sorting purposes can treat as >
             Return 1
           End If

           ' If this point is reached, compare the letters
           Return xparts(1).CompareTo(yparts(1))

        Else

           Return returnvalue

        End If
     End Function
  End Class

Then to do perform the actual sorting: PatientListFinal.Sort(New PatientRoomComparer)

TnTinMN 418 Practically a Master Poster

I suggest that you use the MaskedTextBox control with an initial mask of "#-#######-#-#".

Then in it's KeyPress Event handler:

Private Sub MaskedTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MaskedTextBox1.KeyPress
   If MaskedTextBox1.SelectionStart = 12 Then
     If Char.IsLetter(e.KeyChar) Then
        e.KeyChar = Char.ToUpper(e.KeyChar) ' make  it uppercase
        ' set mask to allow a character
        MaskedTextBox1.Mask = "#-#######-#-A"
        ' Only allow "X"
        If Char.ToUpper(e.KeyChar) <> "X"c Then
           e.KeyChar = "."c 'set to invalid character
        End If
     Else
        MaskedTextBox1.Mask = "#-#######-#-#"
     End If

   End If
End Sub
TnTinMN 418 Practically a Master Poster

I had merged the Date.Add into the LINQ. This should work.

  Select DTRow(grpDT, _
               New Object() {LINENAME, _
                                         New TimeSpan(CType( _
                                                              grp.Average(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks),  _
                                                              Int64 _
                                                            ) _
                                                     ) _
                            } _
              )
TnTinMN 418 Practically a Master Poster

Another alternative is to use a common handler for all the checkboxes.checkchanged event and construct the string on each event.

  Private Sub CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
     Handles CheckBox1.CheckedChanged, _
             CheckBox2.CheckedChanged, _
             CheckBox3.CheckedChanged
     Static Problems As New List(Of CheckBox)
     Dim cb As CheckBox = CType(sender, CheckBox)
     If cb.Checked Then
        Problems.Add(cb)
     Else
        Problems.Remove(cb)
     End If
     Dim sb As New System.Text.StringBuilder(100)
     For i As Int32 = 0 To Problems.Count - 1
        sb.Append(Problems.Item(i).Text)
        If i < Problems.Count - 1 Then sb.Append(", ")
     Next
     TextBox1.Text = sb.ToString
  End Sub
TnTinMN 418 Practically a Master Poster

So what you want is the the arithetic mean (average) of the timespan values? This can be done using the "Average" function instead of the "Sum" function. However the "Average" function will return a value of type "Double" and the TimeSpan constructor takes a "Int64" type, so a type conversion is needed as well.

Change:

  Select DTRow(grpDT, _
               New Object() {LINENAME, _
                             myToday.Add( _
                                         New TimeSpan( _
                                                      grp.Sum(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks) _
                                                     ) _
                                        ) _
                            } _
              )

to:

  Select DTRow(grpDT, _
               New Object() {LINENAME, _
                             myToday.Add( _
                                         New TimeSpan(CType( _
                                                              grp.Average(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks),  _
                                                              Int64 _
                                                            ) _
                                                     ) _
                                        ) _
                            } _
              )
TnTinMN 418 Practically a Master Poster

Why did you not state that you are attempting to create a Yamazumi chart when you first posted?

Creating the functionality you have described can be accomplished using the chart control with some thought put into structuring the source data and a willingness to write some code. Two criteria that you have indicated that you are unwilling to accept.

Good luck.

TnTinMN 418 Practically a Master Poster

You will probably need to go one level lower in the event order; that is why I suggested the KeyDown event. You may need to use the PreviewKeyDown event and set the IsInputKey property.

Majestics commented: Solved the problem. Thanx +8
TnTinMN 418 Practically a Master Poster

I am a bit confused about which control you want to monitor (DGV vs EditControl).

If it is for the DGV and the arrow-up and arrow-down keys, then try using the DGV.KeyDown event.

TnTinMN 418 Practically a Master Poster

So you seem to understand how the chart control plots the points. Instead of relying on the so-called DataBinding supported by this control, create each series in code. You will have one series for each column in the datatable. Add a datapoint for each row in the column.

To get each chart column to be the same color, define an aray of colors. The size of the array would be the number of rows in the datatable. Then while adding each datapoint, set the DataPoint.Color property from this array based on the data source row.

TnTinMN 418 Practically a Master Poster

If you have retrieved the dataset, you can write the schema to a file.

Dim s As IO.Stream = IO.File.OpenWrite("Unknown.xsd")
UnknownDataSet.WriteXmlSchema(s)
s.Close()

After running this code, go to visual studio, and from the Project Menu, select add existing item and add "Unknown.xsd". Then from the Solution Explorer, right-click on Unknow.xsd and select "View Designer". You will see all the returned tables and can inspect the columns via their properties.

TnTinMN 418 Practically a Master Poster

Take a look at your own post!

If you plot 3 series each with 5 points, you get 5 columns with 3 points in each column.

Notice the relation detween the number of points and the number of columns as well as the relation between number of series and number of points per column.

What you wanted was 3 columns with 5 points each.

So make 5 series each with 3 points.

TnTinMN 418 Practically a Master Poster

Sorry, but our required compliance with the guidelines of the National Organization for Computer Homework Excellence Authorization Treaty prevents us from providing you the information you are requesting.