문제

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))

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top