Question

I'm still newbie about this.. i'm trying to make multiple select in condition if the selected rows contains string that I wanted, I've already get the value, but when I tried to get the same value in another rows, it throws Object reference not set to an instance of an object, what I'm trying to do is, if I've already get the selected rows that I need, I want to clear the cells, not remove the rows. I'm using right click event, that I found in some case in stackoverflow. hope you can understanding, thanks for your help and explanation... here is my code

if (e.Button == MouseButtons.Right) {

            rw = dgv_Jadwal_Sewa.HitTest(e.X, e.Y).RowIndex;


            cellValueNota = (int)dgv_Jadwal_Sewa.Rows[rw].Cells[5].Value;
            String cl = Convert.ToString(cellValueNota);


            dgv_Jadwal_Sewa.Rows[rw].Selected = true;

            ContextMenuStrip m = new ContextMenuStrip();

            m.Items.Add("Cancel");
            m.ItemClicked += new ToolStripItemClickedEventHandler(m_ItemClicked);
            m.Show(dgv_Jadwal_Sewa, new Point(e.X, e.Y));


    } 



  public void cancel_Booking()
        {
                String cl = Convert.ToString(cellValueNota);


                foreach (DataGridViewRow row in dgv_Jadwal_Sewa.Rows)
                {
                    if (row.Cells[5].Value.ToString().ToString().Contains(cl))
                    {
                        rw = row.Index;
                        //row.Selected = true;
                        dgv_Jadwal_Sewa.Rows[rw].Selected = true;


                        break;
                    }
                }




        }

it's throw on this line (row.Cells[5].Value.ToString().ToString().Contains(cl))

Was it helpful?

Solution

row.Cells[5] is null or row.Cells[5].Value is null or row is null.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top