vb.net winforms datagridview how to tell where the user clicked in a cell - vb.net

I am adding a custom column to a custom datagridview. One of the options this new datagridcolumn has is the ability show a value and then a button to allow the user to click on the button and something will happen. The button only takes up the right portion of the cell and the rest is a value. This button and value are displayable always and the button should always be able to be clicked on. In datagridview's display mode the value and button are painted. What I need help on is how to tell whether the user clicked on the button portion of the cell. Can someone please provide example code on how to do this?
Thanks,
Greg

Never mind I figured it out. I just put some logic in the cellclick event of the datagridview to get the GetCellDisplayRectangle and converted that to screen points and got where the mouse is on the screen and did a bounds test with the rectangle contains method.

Related

VBA: Can't change Image Control picture after click on element

Setup
I have an Excel VBA UserForm with an Image Control element. When clicking on buttons in the form, the Image Control's Picture source is set / updated with the following code:
Set MyForm.imgControl.Picture = LoadPicture(pathToFile)
Problem
When the user clicks on the Image Control, updating its Picture source doesn't work anymore. The problem occurs, no matter when in the workflow the Image Control is clicked:
Example 1: User clicks a button to set the Picture (and pictures sets correctly). User clicks on Image Control. User clicks a different button to change the Picture -> displayed picture doesn't change.
Example 2: User clicks on Image Control right after Form load. User clicks on button to change the Picture -> displayed picture doesn't change.
If the user never clicks on the Image Control, everything works perfectly smoothly. It's worth noting that clicking on the Image Control doesn't visibly focus it.
Question
Clicking on the Image Control shouldn't make a difference in whether or not the Picture can be updated or not. How can this be done? Or, at least, does anyone know why the explained behavior is happening, or is it just a bug?
The Control does have Click / MouseDown / ... events (which are empty), but they don't take a Cancel parameter.
It does sound like a bug, as you say, but as a workaround, I'd suggest forcing a repaint after changing the picture:
Set MyForm.imgControl.Picture = LoadPicture(pathToFile)
MyForm.Repaint

Object reference in vb. Net when clicking icon

I have a panel that fills with icons of characters. I have a second panel I would like to fill with icons from which character is selected. What is the best way to know which character was selected? Both panels are flow layout panels. I can hover over the character and display the name but I need a good way to reference which character is clicked. The entire object is a user control and another object that retrieves the champion icons to fill the first panel. Thank you.
You need to handle the form.KeyPress event.
Control.KeyPress Event
Examine the KeyEventArgs and go from there.

Don't autoscroll on button click

I am working on an application that works as a dashboard. The form includes a flowlayoutpanel that contains several datagridviews. The flowlayoutpanel is set to autoscroll because there are usually more datagrids than will fit on the visible page. Each datagrid has a buttonclick event that opens a chart form when a particular column (3) is selected. All of the chart functionality works fine. The problem I'm having is that when I click a datagrid that is only partially visible, the page scrolls to bring that datagridview completely onto the page. Because that happens on the click (MouseDown), the page scrolls so quickly that it doesn't actually trigger the clickevent, but selects several cells in the column, as if the user did a click/drag down the column.
What I would like to have happen is when the user clicks on a datagridview that is only partially visible, the chart would open, then the page would scroll on the chart close event. That actually happens if the datagridview in question has focus, but is partially off the page. For example, if I selet the datagridview, then scroll down/up until it is partially off the visible page, then click a cell in column 3. It will display the chart, then autoscroll when I close the chart. But if the datagridview does not have focus, it does the autoscroll thing. I have tried putting the flowlayoutpanel inside another panel, and that worked to some degree, but it was inconsistent.
Sorry for the long description, but I'm trying to be as detailed as possible. Any help would be greatly appreciated. The application is being built in .NET, using VS 2013.
This seems similar to a issue I had with multiple datagridviews inside a panel, this article was the solution for me.
In short, all you need to do is create a custom panel and override the ScrollToControl method. I belive you can do the same with a FlowLayoutPanel.
EDIT:
Your CustomPanel class should look something like this (code converted with developer fusion
Public Class CustomPanel
Inherits System.Windows.Forms.FlowLayoutPanel
Protected Overrides Function ScrollToControl(activeControl As System.Windows.Forms.Control) As System.Drawing.Point
' Returning the current location prevents the panel from
' scrolling to the active control when the panel loses and regains focus
Return Me.DisplayRectangle.Location
End Function
End Class
If this doesn't work you could try inheriting a regular Panel and place a FlowLayoutPanel inside it.

Silverlight Usercontrol in Datagrid does not fire the CellEditEnded event

I have a UserControl that is displaying in a DataGrid. It contains a DatePicker and a Button that opens a Popup control where the user makes a selection that once selected populates a textblock with the result. The DatePicker is the only object that if changed will set off the CellEditEnded event. How can I get the popup controls selectionChanged event to tell the Datagrid that the cell has done as edit?
Turns out I was putting the UserControl inside the CellTemplate when I needed to put something else in that for display and my UC in the CellEditingTemplate. Now it fires as it should. I missed something simple and I should not have. Hope this helps someone else.

VB Datagrid Disable AutoScrolling Focus on Selected column

Kinda new here but needed help and a good friend suggested this site.
My problem is I have a data grid in Visual Basic, it works fine but as the columns extend past the width of the window I needed a scroll bar. This is where the problem arose. When a column past the 4th is clicked the scrollbar will shift to give it focus. As there are check boxes here they are constantly clicked and when they are the scroll bar shifts but the button isn't checked and must be clicked again.
I was hoping there was a way to disable this Auto focus so clicking a column will not cause the scrollbar to move.
Any help would be greatly appreciated. ^__^
There is no real autoscroll in vb, one of the sub method was causing it to jump by checking another cell off the screen then defaulting back to the one shown which had the appearance of a jump.