mardi 21 avril 2015

No overload for "method" matches delegate 'System.EventHandler'?

private async void submitRequestButton_Click(DateTime dateFormat, DateTime startFormat, DateTime endFormat, EventArgs e)
    {
        ParseObject request = new ParseObject("Shifts");
        request["Name"] = ParseUser.CurrentUser.Username;
        request["Shift"] = shiftBox.Text;
        request["Rental"] = rentalBox.Checked;
        request["Location"] = locationBox.Text;
        request["Date"] = dateFormat.ToString("MMMM dd, yyyy");
        request["startTime"] = startFormat.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));
        request["endTime"] = endFormat.ToString("t", CultureInfo.CreateSpecificCulture("en-us"));

        await request.SaveAsync();
    }

    private DateTime datePicker_ValueChanged(DateTime dateFormat, EventArgs e)
    {
        dateFormat = datePicker.Value;

        return dateFormat;
    }

    private DateTime startTimePicker_ValueChanged(DateTime startFormat, EventArgs e)
    {
        startFormat = startTimePicker.Value;

        return startFormat;
    }

    private DateTime endTimePicker_ValueChanged(DateTime endFormat, EventArgs e)
    {
        endFormat = endTimePicker.Value;

        return endFormat;
    }

I don't understand why I am getting this error for methods 2, 3 and 4.

No overload for "method" matches delegate 'System.EventHandler'?

If you need to see more code just let me know. I'm pretty sure everything is hooked up properly.

It looks like the error is coming from: this.datePicker.ValueChanged += new System.EventHandler(this.datePicker_ValueChanged); (the same goes for the other 2 methods).

Please help!

DesignSurface: Can't delete controls

I'm currently working on a project involving DesignSurfaces.

In the program load event, I load a form with 3 textboxes, 3 labels and a button. To manage these controls, I have a ContextMenuStrip with MenuItems containing the StandardCommands Cut, Copy, Paste and Delete. However, when I try any of these actions, It'll throw an InvalidOperationException which says something like "The inherited component 'textBox1' cannot be deleted" (Unfortunately, I don't have the exception message in english, but through googling I found that it might be this one: "Cannot remove or destroy inherited component") If I add a control runtime and try to delete it, everything works fine (Cut, Copy, Paste too).

Here's the code for the ContextMenuStrip:

public void ShowContextMenu( CommandID menuID, int x, int y ) {
            ContextMenu contextMenu = new ContextMenu();

            MenuCommand command = FindCommand( StandardCommands.Cut );
            if( command != null ) {
                MenuItem menuItem = new MenuItem( "Cut", new EventHandler( OnMenuClicked ) );
                menuItem.Tag = command;
                contextMenu.MenuItems.Add( menuItem );
            }
            command = FindCommand( StandardCommands.Copy );
            if( command != null ) {
                MenuItem menuItem = new MenuItem( "Copy", new EventHandler( OnMenuClicked ) );
                menuItem.Tag = command;
                contextMenu.MenuItems.Add( menuItem );
            }
            command = FindCommand( StandardCommands.Paste );
            if( command != null ) {
                MenuItem menuItem = new MenuItem( "Paste", new EventHandler( OnMenuClicked ) );
                menuItem.Tag = command;
                contextMenu.MenuItems.Add( menuItem );
            }
            command = FindCommand( StandardCommands.Delete );
            if( command != null ) {
                MenuItem menuItem = new MenuItem( "Delete", new EventHandler( OnMenuClicked ) );
                menuItem.Tag = command;
                contextMenu.MenuItems.Add( menuItem );
            }

            DesignSurface surface = (DesignSurface) _serviceProvider;
            Control viewService = (Control) surface.View;

            if( viewService != null ) {
                contextMenu.Show( viewService, viewService.PointToClient( new Point( x, y ) ) );
            }
        }


private void OnMenuClicked( object sender, EventArgs e ) {
            MenuItem menuItem = sender as MenuItem;
            if( menuItem != null && menuItem.Tag is MenuCommand ) {
                MenuCommand command = menuItem.Tag as MenuCommand;
                command.Invoke();
            }
        }

I can't figure out what the problem is here.

Did someone here experience a similiar issue? Or any ideas on how to solve this?

TileItem Click Event not working properly?

I have a TileItem in a tilecontrol (DevExpress). On click this method is fired

private void tileItem1_ItemClick_1(object sender, DevExpress.XtraEditors.TileItemEventArgs e)
        {
            if (GetForegroundWindow() == Process.GetCurrentProcess().MainWindowHandle)
            {
                MessageBox.Show("It is focused!");
                //do some magic here
            }
            else
            {
                MessageBox.Show("It is not focused!");
                this.Activate();
            }
        }

My problem is that even if my form is not focused, it will think that it is focused and always triger the first condition of the if statement. I want to activate the window when the tileitem is clicked IF the window is not focused. Isn't this the proper way to do it? What i am thinking is that the method is triggered after the mouse is released so the window has already taken focus by that time. If this is the problem then which is the solution to achieve what i am trying to do?

Thanks is advance.

Combobox displaying list instance instead of the actual value names

I am populating a combobox with data from database. The data is being stored in a list. When I run the form, the combobox displays the right amount of GroupPlayers i.e. 2 but doesn't actually display the name of these groups, instead it displays the list (i think it's called, correct me if i am wrong) instance i.e. group.

Main form:

    public void Groups() {
        var smallGroups = new List<GroupsPlayers>();

        //sql connections query etc etc is here 

        while(rd.Read())
        {
            var currentPlayer = new GroupsPlayers() {
                GroupID = rd["GroupID"].ToString(),
                GroupName = rd["GroupName"].ToString(),

            };

            smallGroups.Add(currentPlayer);
        }

        if(userResponse == DialogResult.Yes)
        {
            UpdatePlayer frmPlayers = new UpdatePlayer(smallGroups);
        }
    } 

UpdatePlayer form

 public class GroupsPlayers
    {
        public string GroupID { get; set; }
        public string GroupName { get; set; }
    }


List<GroupsPlayers> _GroupPlayers;
UpdatePlayer (List<GroupsPlayers> GroupPlayers)
{
    _GroupPlayers = GroupPlayers; 
}

private void BindCb()
        {
            cb.DataSource = _GroupPlayers;
            cb.DisplayMember = "GroupName";

        }

Also, when I use cb.ValueMemeber = "GroupID"; I get the error

Cannot bind to the new display member

In C#, WebBrowser1,DocumentComplete fires 4 times

I have a button that has the following code

 webbrowser1.Navigate(testURL);

In my

 private void webbrowser1_Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
       if (e.Url.Equals(psyncBrowser.Url))
        {
            Console.WriteLine("Now it is really done");
            MessageBox.Show("Loaded " + psyncBrowser.Url);
            webbrowser1.Stop();
        }
 }

I get a console message with the message 4 times!!! HOw can I stop this from happening?

Mouse pointer position when pointer is not on winform

I'm able to get the mouse position when it is within the form. Here is my code-

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    lblXPosition.Text = MousePosition.X.ToString();
    lblYPosition.Text = MousePosition.Y.ToString();
}

But it does not work when the pointer is outside the form. Any suggestion?

Disabling scrollbar of Winform control inside WPF control

I have a WindowsFormsHost, with a Winform control in it, inside a WPF Tab item.

I've set the scrollbar to 'Hidden' on the Tab Control, the Tab Item itself, the WindowsFormsHost AND the Winform control inside the Host.

The scrollbars are still there, so at this point I'm not sure where they're coming from. I've also disabled the scrollbar on the entire window itself.

I have ScrollViewer.HorizontalScrollBarVisibility="Hidden" set on all the aforementioned controls.