DataGridView.rows.Cells.Style.BackColor doesn't work with MdiParent in form load event - vb.net

It really drives me crazy, I have a form, I am calling a public sub called "timerss" in the form load event, when i run my form the sub "timerss" works perfectly, but when i add "Me.MdiParent = MDIParent1" in load event the sub "timerss" doesn't work!! i am really confused here!! any idea please.
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MdiParent = MDIParent1
timerss()
End Sub
update1:\ check the print screen of the result when running my form with and without setting MdiParent!
update2: I managed to fix part of the problem which is i got the data but what i want now is to set the color of the time cells with red, as i said the sub don't want to work, the timerss sub is:
For m As Integer = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(m).Cells(4).Value > DataGridView1.Rows(m).Cells(9).Value Then
DataGridView1.Rows(m).Cells(4).Style.BackColor = Color.Red
MsgBox("red")
End If
Next
as u c in the above code i put a msgbox just to make sure that the code is working, so when i run my form the msgbox appears, but the backcolor function doesn't work when i set the MdiParent.

I don't know why the behavior is different without MDIParent, but you could try calling the sub from the DataBindingComplete event.
I had a similar problem and solved it using the event.

Related

Getting a panel within a panel with mouse position

I've been looking for this thing... It should be working yet it is not. There must be something I don't get understand or that I'm missing. It's quite a simple problem but I can't seem to solve it.
I got Panel1 and Panel2 as shown in this picture.
I want to catch when mouse is over Panel2 within Panel1 MouseLeave event. My code goes like this :
Private Sub Panel1_MouseLeave(sender As Object, e As EventArgs) Handles Panel1.MouseLeave
If sender.ClientRectangle.Contains(PointToClient(Control.MousePosition)) Then
For Each ctrl As Object In sender.controls
If ctrl.ClientRectangle.Contains(PointToClient(Control.MousePosition)) Then Exit Sub
Next
If Not IsNothing(sender.BackgroundImage) Then sender.BackgroundImage = Nothing
End If
End Sub
Private Sub Panel2_MouseLeave(sender As Object, e As EventArgs) Handles Panel2.MouseLeave
If Not sender.ClientRectangle.Contains(PointToClient(Control.MousePosition)) Then
If Not IsNothing(sender.BackgroundImage) Then sender.BackgroundImage = Nothing
End If
End Sub
I'm successfully getting into the first if, but the 2nd one within the For Each just never equals true. So I thought maybe there was a problem with the 2nd panel, so I tried placing the same code for Panel2 MouseLeave, but it's working just fine.
I really need this code to work for a big control flickering problem I'm having.
Thanks to Hans Passant for the hint. I just had to call the PointToClient with the right control :
Private Sub Panel1_MouseLeave(sender As Object, e As EventArgs) Handles Panel1.MouseLeave
If sender.ClientRectangle.Contains(Panel1.PointToClient(Control.MousePosition)) Then
For Each ctrl As Object In sender.controls
If ctrl.ClientRectangle.Contains(ctrl.PointToClient(Control.MousePosition)) Then Exit Sub
Next
If Not IsNothing(sender.BackgroundImage) Then sender.BackgroundImage = Nothing
End If
End Sub

Drag and drop an image into a RichTextBox

I am updating code done in VB 4, where I have a RichTextBox. I need to be able to drag-and-drop an image from Windows Explorer into the RTB. Unfortunately, I am unable to get the drag-and-drop to work.
I've created a much more simple Windows Form program to try to resolve this, but have made no progress. I begin by setting AllowDrop to True.
Public Sub New()
InitializeComponent()
Me.DragAndDropTextBox.AllowDrop = True
End Sub
I then create handlers for the RTB. These are taken directly from MSDN.
Private Sub DragAndDropTextBox_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles DragAndDropTextBox.DragEnter
' Check the format of the data being dropped.
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
' Display the copy cursor.
e.Effect = DragDropEffects.Copy
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub DragAndDropTextBox_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles DragAndDropTextBox.DragDrop
System.Windows.Forms.DragEventArgs) Handles DragAndDropTextBox.DragDrop
Dim img As Image
img = Image.FromFile(e.Data.GetData(DataFormats.FileDrop, False))
Clipboard.SetImage(img)
Me.DragAndDropTextBox.SelectionStart = 0
Me.DragAndDropTextBox.Paste()
End Sub
When I grab an image in Explorer and drag it over my window, I get the circle with a slash. I have put breakpoints on the first line of each of the handlers, and they are never reached. I have looked at several pages, and they all seem to give the same process, so I must be missing something simple.
I am not worried right now about pasting the image into the text box; I know I need to work on that. I am only trying to capture the image, but the handler methods do not seem to be getting called.
UPDATE
After quite a bit of experimentation, I found that the actual issue is with my Visual Studio 2010, which I always run as administrator. When I run the program from an exe, the drag-and-drop works. When I try running from VS in debug, it does not. Has anyone experienced this before?
If anyone could shed some light on this, I would be very grateful.
Try getting rid of the InitializeComponent() call in your Sub New function. When I did that, I was able to detect the DragEnter event. Here is the code I tested (I created a simple WinForm and put a RichTextBox on it called DragAndDropTextBox):
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DragAndDropTextBox.AllowDrop = True
End Sub
Private Sub DragAndDropTextBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DragAndDropTextBox.DragEnter
Debug.Print("Entering text box region")
' Check the format of the data being dropped.
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
' Display the copy cursor.
e.Effect = DragDropEffects.Copy
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub DragAndDropTextBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DragAndDropTextBox.DragDrop
Dim img As Image
img = Image.FromFile(e.Data.GetData(DataFormats.FileDrop, False))
Clipboard.SetImage(img)
Me.DragAndDropTextBox.SelectionStart = 0
Me.DragAndDropTextBox.Paste()
End Sub
End Class
The InitializeComponent() call should appear in your code (I believe) when you add your own custom controls to a form. Otherwise, I don't think you need to call it.
It turned out that the Drag-And-Drop was working when running the code from an exe, but not from within Visual Studio. More searching turned up this answer, which states that Drag-And-Drop does not work in Visual Studio when it is run as an Administrator. I ran it with normal permissions, and the code worked.

Why dont the Command Button excecute the form

Good day. I Created a form that worked perfectlt, after testing the Command Button a few times and entering information into the form I decided to straiten out the form and make it tidy. after saving the form i tried to click the Command butten but this time it gave me a Error 424. Object Required.
(I tried to upload pictures with no success)
When I Check the Debug it highlight the .show command.
Private Sub CommandButton1_Click()
ClaimUserForm.Show
End Sub
I also tried:
Private Sub CommandButton1_Click()
Dim Claim as ClaimUserForm
Set Claim = new ClaimUser
claim.show
End Sub
But the debug re-appear.
in the form property window the form name is ClaimUserForm
Please help, I cant understand why it suddenly gave this problem.
Thanks
Is your button working properly? It seems it's missing the sender-object and the events.
Also set is not necessary.
Private Sub CommandButton1_Click(sender As Object, e As EventArgs) Handles CommandButton1.Click
Dim Claim As ClaimUserForm = New ClaimUser
Claim.Show
End Sub
sender As Object, e As EventArgs and Handles Button1.Click are missing.

How to automate TextBox control for Enter key

I have to do the following for each textbox control.
If e.KeyCode = Keys.Enter Then
Me.DateDateTimePicker.Focus()
End If
Should there be a For Next loop option, pls mention under which Sub Routine I should code the loop.
From what you're saying, I think this should be placed within the KeyPressed event within the text box you are trying to run this piece of code from. You can also integrate multiple events for many controls into a single method.
Hope this helps!
You can but your code inside a 'KeyUp' event and then alter the 'KeyUp' event of one textbox to handle more than one textbox keyups event, but only one code can be executed for all of them,
check this:
Private Sub ***TextBox1_KeyUp***(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyUp, ***TextBox2.KeyUp***, ***TextBox3.KeyUp***
'*************
'Write your code Here
'*************
End Sub
As others said, you can use only one method to handle multiple events.
Moreover, you can execute sender-customized code:
Sub MyEventHandler(sender as Object, e as Event) Handles obj.ev, obj2.ev, obj3.ev
'Use sender property (properly casted, if necessary)
'to run sender specific code
DirectCast(sender, TextBox).Text = "foo"
End Sub

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