开发者

DataGridView with ContextMenu assigned to column and a MessageBox

I have a DGV that has its datasource set to a BindingList. There is also a ContextMenu assigned to a column in the DGV. There is a MenuItem set on the ContextMenu that calls a MessageBox on the click event.

Everything works fine and the Methods are called and the MessageBox with YesNo responses do what they are susppose to.

The problem that I am having is that when the MessageBox's click event occurs (Yes or No) it does it's job and goes away. If the same routine is called a second time, it again does it's job with no problem, then reappears. If I click Yes or No it goes away. If I call it a third time the MessageBox appears again does its job and reappears twice. As if everytime it's being called its iterating and calling itself again that amount of times. This will occur for everytime it's called.

The BindingList is built using a Class with nested properties and all data elements are present.

I tried using just a blank MessageBox with no DialogResults and no change. I even tried using the DGV's RaiseListChangedEvents=false in the ContextMenu click event and the DGV's Cell Enter Click Event.

I've stepped through my code and and no matter what the Class with the nested properties always gets called and causes the ContextMenu's click event to be called again and again... I figure this is by design since a BindingList will always AutoUpdate when a cell's value is accessed or changed.

ContextMenu's Column is a Button and is readonly.

So how do I either catch the MessageBox after it's run the first time or stop the BindingList from auto updating. My List draws its data from a Web Reference and I handle updates through the methods provided from the API. The only reason I'm using a BindingList is because the DGV doesn't work with just a List .

Thank you for any help or guidance. (First time posting, but have gathered and used a lot of info from here)

Here's some code:

_requestsView.AutoGenerateColumns = false;
            _edit.DataPropertyName = "RequestId";
            _patient.DataPropertyName = "Patient";
            _dateSubmitted.DataPropertyName = "Date";
            _completedBy.DataPropertyName = "CompletedBy";
            _completedOn.DataPropertyName = "CompletedOn";
            _procedure.DataPropertyName = "Procedure";
            _stat.DataPropertyName = "Stat";
            _viewReport.DataPropertyName = "ViewReport";
            _selectedSpecialist.DataPropertyName = "SelectedSpecialist";
            _status.DataPropertyName = "Status";
            _rate.DataPropertyName = "Rating";

            _requestsView.DataSource = _requestsBinding;
// _cancelRequest_Click is ContextMenu MenuItem

void _cancelRequest_Click(object sender, EventArgs e)
    {

        MessageBox.Show("test");
    }

private void _requestsView_CellEnter(object sender, DataGridViewCellEventArgs e)
    {

        if (_requestsView.CurrentRow != null)
            if (_requestsView.CurrentRow.Cells["_viewReport"].Selected)
                try
                {
                 var requestNumber = (int)_requestsView.CurrentRow.Cells ["_viewReport"].Value;
                    var letter = Api.Client.getCompletedLetter(UseSession.SessionId,  requestNumber);
开发者_JAVA百科                    var convertedLetter = Convert.FromBase64String(letter);
                    var requestNumberToString = Convert.ToString(requestNumber);
                    var tmpfile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), requestNumberToString + @".pdf");
                    var view = new ViewLetter(requestNumberToString, tmpfile);

                    File.WriteAllBytes(tmpfile, convertedLetter);

                    view._pdf.LoadFile(tmpfile);
                    view._pdf.PerformLayout();
                    view._pdf.Refresh();
                    view._pdf.setShowToolbar(true);
                    view._pdf.setZoom(100);
                    view.Show();
                    view.Activate();
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                }

        if (_requestsView.CurrentRow != null)
            if (_requestsView.CurrentRow.Cells["_edit"].Selected)
                _edit.ContextMenuStrip.Show(Cursor.Position.X, Cursor.Position.Y);

        if (_requestsView.CurrentRow != null)
            if (_requestsView.CurrentRow.Cells["_rate"].Selected)
                _rate.ContextMenuStrip.Show(Cursor.Position.X, Cursor.Position.Y);

    }

public class Requests
{
    private int _requestId;
    private DateTime _date;
    private string _patient;
    private string _completedBy;
    private string _completedOn;
    private string _procedure;
    private string _stat;
    private int _viewReport;
    private Specialists _selectedSpecialist;
    private string _status;
    private int _rating;

    public Requests()
    { }

    public Requests(string stat)
    {
        _stat = stat;
    }

    public int RequestId
    {
        get { return _requestId; }
        set { _requestId = value; }
    }

    public DateTime Date
    {
        get { return _date; }
        set { _date = value; }
    }

    public string Patient
    {
        get { return _patient; }
        set { _patient = value; }
    }

    public string CompletedBy
    {
        get { return _completedBy; }
        set { _completedBy = value; }
    }

    public string CompletedOn
    {
        get { return _completedOn; }
        set { _completedOn = value; }
    }

    public string Procedure
    {
        get { return _procedure; }
        set { _procedure = value; }
    }

    public string Stat
    {
        get { return _stat; }
        set { _stat = value; }
    }

    public int ViewReport
    {
        get { return _viewReport; }
        set { _viewReport = value; }
    }

    public Specialists SelectedSpecialist
    {
        get { return _selectedSpecialist; }
        set { _selectedSpecialist = value; }
    }

    public string Status
    {
        get { return _status; }
        set { _status = value; }
    }
    public int Rating
    {
        get { return _rating; }
        set { _rating = value; }
    }
}


Just wanted to update this and close it. I figured out a work around that sets a boolean true or false during different stages of events being called. If the boolean is set to true I just do a return to get out of the methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜