Question: I'm compiling a program on gcc by using `-Wbad-function-cast` flag. The gcc show the following warning: 

`cast does not match function type`

this is line of warning: `int ret = (int)`[`FindExecutable(file, NULL, result)`](http://msdn.microsoft.com/en-us/library/windows/desktop/bb776419%28v=vs.85%29.aspx)

The question is: it's possible remove it? maybe casting to another windows data type, but that I handling it as an integer.

Answer: 
**UPDATE:**

Instead of

```
 If dragIndex < 0 Then dragIndex = DataGridView1.RowCount - 1

```

change to

```
 If dragIndex > -1 Then 
      'action if not selected in the row header and blank space
 else
      'return error if selected in the column header and blank space
 end if

```

then a error occurs when you drag a row to the "blank zone", if you don't believe me, you must to try it.

the final code (Only for the part "The drag events") is this:

```
  Private Sub DataGridView1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles DataGridView1.DragDrop
        Dim p As Point = DataGridView1.PointToClient(New Point(e.X, e.Y))
        dragIndex = DataGridView1.HitTest(p.X, p.Y).RowIndex
    'Determine if dragindex is valid row index       
    If dragIndex > -1 Then
        If (e.Effect = DragDropEffects.Move) Then
            Dim dragRow As DataGridViewRow = CType(e.Data.GetData(GetType(DataGridViewRow)), DataGridViewRow)
            DataGridView1.Rows.RemoveAt(fromIndex)
            DataGridView1.Rows.Insert(dragIndex, dragRow)
            'Add this line of code if you want to put selected rows to the rows that change
            DataGridView1.Rows(dragIndex).Selected = True
        End If 
       Else 'Do any message here if selected in column header and blank space. 
       End If
    End Sub

```
1.5 improvements for the event *GridView.DragDrop*:

1. The first 50% improvement, To avoid the descriped error you can also use 

```
Private Sub DgvSearchFieldCurrent_DragDrop( _
   ByVal sender As  Object, ByVal e As DragEventArgs) _
   Handles DgvSearchFieldCurrent.DragDrop

Dim LclDgv As DataGridView = CType(sender, DataGridView)

If dragIndex > -1 AndAlso dragIndex < LclDgv.RowCount -1 Then

```
2. Second is to set focus to the current row and the first cell:

```
LclDgv.Rows.Insert(dragIndex, dragRow)

LclDgv.Rows(fromIndex).Selected = False
LclDgv.Rows(dragIndex).Selected = True

For Each C As DataGridViewColumn In LclDgv.Columns
  LclDgv(C.Index, fromIndex).Selected = False
Next

LclDgv(0, dragIndex).Selected = True

```