try abc

try abc

  • 1.4k
  • 306
  • 487.4k

problem selecting cell after datagridviewcell Drop Down

Apr 24 2010 2:05 AM
Hello.. 
I want to drag n drop Single cell.. such that i can copy the value form one cell to another.. i used following code .. everything works fine but  problem is that  after dropping cell the new cell where i am dropping value doesn't  highlight. and highlight remain on the first cell where i start dragging... 
Here is the code..   i try to set current cell .. but still didn't work.
 
  1. private void dataGridView1_MouseDown(object sender, MouseEventArgs e)  
  2. {  
  3.          if (e.Button == MouseButtons.Left)  
  4.          {  
  5.                    DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y);  
  6.                      
  7.                      if (info.RowIndex >= 0 && info.ColumnIndex >= 0)  
  8.                      {  
  9.                                string  text = Convert.ToString(dataGridView1.Rows[info.RowIndex].Cells[info.ColumnIndex].Value);  
  10.                                if (text != null)  
  11.                                {  
  12.                                          dataGridView1.DoDragDrop(text, DragDropEffects.Copy);  
  13.                                }  
  14.                      }  
  15.          }  
  16.            
  17. }  
  18. private void dataGridView1_DragEnter(object sender, DragEventArgs e)  
  19. {  
  20.          e.Effect = DragDropEffects.Copy;  
  21. }  
  22. private void dataGridView1_DragDrop(object sender, DragEventArgs e)  
  23. {  
  24.          if (e.Data.GetDataPresent(typeof(System.String )))  
  25.          {  
  26.              DataGridView dgv = (DataGridView)sender;  
  27.              Point p = dgv.PointToClient(new Point(e.X, e.Y));  
  28.              DataGridView.HitTestInfo info= dgv.HitTest(p.X, p.Y);  
  29.              if (info.RowIndex >= 0 && info.ColumnIndex >= 0)  
  30.              {  
  31.                          
  32.                        dataGridView1[info.ColumnIndex,info.RowIndex].Value = e.Data.GetData(typeof(System.String));  
  33.                        dgv.CurrentCell = dataGridView1[info.ColumnIndex, info.RowIndex];  
  34.                        dgv.CurrentCell.Selected = true;  
  35.                          
  36.              }  
  37.          }    

 

Answers (2)