1 Replies - 4324 Views - Last Post: 26 October 2010 - 05:23 AM Rate Topic: -----

#1 c#think#:)  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 112
  • Joined: 17-March 10

DataGridView.SelectionMode question...

Posted 25 October 2010 - 03:19 AM

Hey guys!

I have surfed the web, but no luck so far... I hope u can help me out here.

I have a DataGridView wich is populated form DataSet. There are 6 columns. First one is not displayed(ID). So if i count ColumnIndex i get 5. I set DataGridView.SelectionMode to FullRowSelect, i need it so user could select a row and delete it. That works perfectly. But i also need to use CellSelect because on the last column DoubleClick event i call out another form. So, if i use CellSelect, then i get ColumnIndex like this:
DataGridView.SelectedCells[0].ColumnIndex


i need to determine ColumnIndex, because DoubleClick event should be fired only if ColumnIndex is 5. But the above code will not work if i set SelectionMode to FullRowSelect. And if i set SelectionMode to CellSelect so that i can determine ColumnIndex then user cannot select full row to delete it. Is there another way to obtain ColumnIndex while SelectionMode is set to FullRowSelect?

Any ideas?

Thanks in Advance.

Is This A Good Question/Topic? 0
  • +

Replies To: DataGridView.SelectionMode question...

#2 c#think#:)  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 112
  • Joined: 17-March 10

Re: DataGridView.SelectionMode question...

Posted 26 October 2010 - 05:23 AM

Well, since nobody helped me, i managed to solve it my way(it took me a while, cause i am not experienced with programming)...

This is for those users, who had similar problems... DataGridView.SelectionMode is set to CellSelect.

When user presses Delete key on keyboard

private void DancersDGV_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                DialogResult diagResult = MessageBox.Show("Delete selected dancer?", "Delete dancer", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (diagResult == DialogResult.Yes)
                {                   
                    DancersDGV.Rows.RemoveAt(DancersDGV.SelectedCells[0].RowIndex);
                }
            }
        }        



And remember,
C#Think#;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1