Finding series item clicked in a chart in VB 2008 - vb.net

I am using VB 2008 with the Microsoft Chart Controls for .NET Framework. Using a pie chart, I would like to find the selected item when the chart is clicked or double clicked.
I am have the click and doubleclick events as shown here, which I have confirmed is being hit, and the the eventarts contains the x,y position of the click.
Private Sub Chart_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
Private Sub Chart_Click(ByVal sender As Object, ByVal e As System.EventArgs)
What I would really like to find out is what series item was clicked or doubleclicked (what pie slice).
This is being done in a windows forms application.
How do I get the series item clicked or doubleclicked?

The following gives you the chart element under the Mouse.
Dim HTR as HitTestResult
Dim SelectDataPoint As DataPoint
HTR = Chart1.HitTest(e.x,e.y)
SelectDataPoint = Chart1.Series(0).Points(HTR.PointIndex)
Note that you should probably do some checking to make sure it is a Series that the user clicks on by checking the HTR.ChartElementType. Oh, and this should go in a MouseUp event, since the e that I use are MouseEventArgs.

Related

Send data to another xaml in Windows Phone 8.1 - VB.NET

How can I get a variable in one xaml(when the button is clicked) to appear in another xaml in a textbox.
Basically once the button is clicked in Menu.xaml the name variable is displayed in a text box in Basket.xaml. How can I go about doing that?
Button in Menu.xaml
Private Sub VanButton_Click(sender As Object, e As RoutedEventArgs) Handles VanButton.Click
Dim Name As String = "Vanilla"
End Sub
Variable Name into Basket.xaml textbox once button is clicked in Menu.xaml
Private Sub IcecreamChosen_TextChanged(sender As Object, e As TextChangedEventArgs) Handles IcecreamChosen.TextChanged
End Sub
The app is developed in VB.NET , Visual Studios 2015. I am new to this and have no idea on how to make it work this way.
You have to give a name to your textbox and the in the button click event handle you can write yourtextboxname.Text = variabile
Anyway I suggest you to start using databinding approach. Xaml is databinding based! :)

vb.net Add Custom validation Events in textbox

i am making vb.net application in which there are 10 textbox in which i am changing background color when it got focus and lost focus. and adding validation number or character only. is there any way i can set or add custom code that every textbox added in form change color on got focus and lost focus and can assign textbox validation number only, alphanumeric. i don't want to add code on every event on keypress , gotfocus and lostfoucs. i just want to set it as default property of text box
here is my code
Private Sub txtProductDescc_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtProductDescc.GotFocus
txtProductDescc.BackColor = interfaceDesign.gotFocusTxtColor
End Sub
Private Sub txtProductDescc_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtProductDescc.LostFocus
txtProductDescc.BackColor = interfaceDesign.lostFocusTxtColor
End Sub
One way, which I am using myself often, is to make an array of textboxes. This way they all share the same "code" for every event and you can select them by index if you need to address a specific item.
Updated
You can also capture key events on the main form:
C# capture main form keyboard events
How do I capture Keys.F1 regardless of the focused control on a form?

VB.Net Chart created in code - how to get X value from click event on chart?

I have a chart that is created in code in a VB.Net WinForms application. When the form runs the chart is added to a panel and displays on the form. All is good.
I am trying to return the cursor properties for the chart, specifically I am trying to get the x-coordinate value. I know I can use Me.Chart1.ChartAreas(0).CursorX.Position to get this value when using a chart created in the form and placed in the click event for that chart.
At the moment I have a click event for the code generated chart. The arguments being passed are as below:
Private Sub chart1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles _Chart.Click
When I step through the code, e returns the mouse position for the chart but the cursor position (_Chart.ChartAreas(0).CursorX) returns "NaN".
Can anyone point me in the right direction?
I have managed to solve this one.
The Chart created in code must be done WithEvents. The method responding to the Click handler needs to be passing MouseEventArgs rather than System.EventArgs as below:
Private Sub chart1_Click(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles _Chart.Click
The X value can be returned using
_Chart.ChartAreas(0).AxisX.PixelPositionToValue(e.X)

Tooltip showing twice

I'm showing a ToolTip on a certain button's MouseHover event. If I go over it once it works but if I leave, wait for the tooltip to disapear and come back on the button, it appears twice. I tried cancelling it on MouseLeave but it still appear twice the seocnd time.
Private Sub someButton_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles someButton.MouseHover
Dim tooltipSearch As New ToolTip()
tooltipSearch.Show("I'm a tooltip"), someButton)
End Sub
Private Sub someButton_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles someButton.MouseLeave
Dim toolTip As New ToolTip()
toolTip.GetToolTip(someButton)
toolTip.Hide(someButton)
toolTip.Dispose()
End Sub
Am I missing something obvious?
You are using the ToolTip not in the way it should be used (also look at the documentation :) ). It is just like any other control, start by dragging it onto your form (like you do with other controls).
If you have no dynamic text to be displayed in your tooltip, you can easily set the text in your constructor, using the method SetToolTip. If you do want some dynamic text, you can use this method in your MouseHover event.
Apart from that, you shouldn't do anything anything else. Just set the right delays on your tooltip and it should work all fine.
Private Sub someButton_MouseHover(sender As Object, e As System.EventArgs) _
Handles someButton.MouseHover
ToolTip1.SetToolTip(someButton, "My name is Steve chamba from south Africa")
End Sub
The answer about dragging the ToolTip control to the form is great. There is a subtlety with Button controls though. They seem to automatically set the tool tip to the text of the button, so if you also call ToolTip1.SetToolTip(myButton, "Button Text") then dot-net draws two copies of the tool tip text when you hover over the button.

vb.net winform 2008 datagrid doubleclick event not firing

i have a databound datagrid in vb.net 2008. This is a program where i use the double click event multipal times.. but for some reason on a new form it's not working anymore. In code behind i selected the datagrid and double click event. when i double click on teh grid in debug mode, it never fires off the event(i put a breakpoint in). I've tried several other events and none of them are firing.
Here is what the event look like
Private Sub dgWho2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgWho2.DoubleClick
End Sub
and here is what it looks like for one that is working on another form
Private Sub dgQueryStats_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgQueryStats.DoubleClick
For Each O As asr.QueryStat In Os
If O.RowID = CInt(Me.dgQueryStats.Tag.ToString) Then
Me.lblQuery.Text = O.Text
End If
Next
Me.cmdCopyQuery.Visible = True
End Sub
in comparing the properties of the two datagrid, other than the name and the binding, they look the same as well. wondering if anyone has an idea.
thanks
shannon
Err... found my problem.. i had a datagrid.enabled=false stuck down in some code...
Sorry about that
shannon