Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Job data buttons missing limits checks lead to crash #26

Open
MaWa53 opened this issue Jul 15, 2015 · 1 comment
Open

Job data buttons missing limits checks lead to crash #26

MaWa53 opened this issue Jul 15, 2015 · 1 comment

Comments

@MaWa53
Copy link

MaWa53 commented Jul 15, 2015

Here are the already modified event handlers, since I can't commit to SVN.

 public int GetGridRow(DataGridView grid) {
        if (grid.CurrentCell != null)
            return grid.CurrentCell.RowIndex;
        else
            return -1;
    }

    private void Up_button_Click(object sender, EventArgs e) {
        var row = GetGridRow(JobData_GridView);
        if (row <= 0) return;
        Global.MoveItem(Cad.JobData, row, -1);
        JobData_GridView.CurrentCell = JobData_GridView[0, row - 1];
    }

    private void Down_button_Click(object sender, EventArgs e) {
        var row = GetGridRow(JobData_GridView);
        if (row >= JobData_GridView.Rows.Count-1) return;
        if (row != -1)
        {
            Global.MoveItem(Cad.JobData, row, +1);
            JobData_GridView.CurrentCell = JobData_GridView[0, row + 1];
        }
    }

    private void DeleteComponentGroup_button_Click(object sender, EventArgs e) {
        if (JobData_GridView.Rows.Count > 0)
        {
            var row = GetGridRow(JobData_GridView);
            Cad.JobData.RemoveAt(row);
        }
    }
@thethereza
Copy link

tweaked and added

    public int GetGridRow(DataGridView grid) {
        return (grid.CurrentCell != null) ? grid.CurrentCell.RowIndex : -1;
    }

    private void Up_button_Click(object sender, EventArgs e) {
        var row = GetGridRow(JobData_GridView);
        if (row <= 0) return;
        Global.MoveItem(Cad.JobData, row, -1);
        JobData_GridView.CurrentCell = JobData_GridView[0, row - 1];
    }

    private void Down_button_Click(object sender, EventArgs e) {
        var row = GetGridRow(JobData_GridView);
        if (row >= JobData_GridView.Rows.Count - 1) return;
        if (row != -1) {
            Global.MoveItem(Cad.JobData, row, +1);
            JobData_GridView.CurrentCell = JobData_GridView[0, row + 1];
        }
    }

    private void DeleteComponentGroup_button_Click(object sender, EventArgs e) {
        if (JobData_GridView.Rows.Count > 0) {
            var row = GetGridRow(JobData_GridView);
            if (row != -1)  Cad.JobData.RemoveAt(row);
        }
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants