开发者

Popping up a TextBox on mouse click over a PictureBox for adding to grid view

I try to apply http://stackoverflow.com/questions/5549150/popping-up-a-textbox-on-mouse-click-over-a-picturebox-for-adding-custom-note-to-p to my project in different way.When I click on picturebox, textbox should appear and after it closed on that clicked position that entered value should go to datagridview by row by row with previous data.

But in this method all the time previous data will clear. How should I adjust it

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
  // in this case we create a TextBox, but the
  // PopupForm can hold any type of control.
  TextBox textBox = new TextBox();
  Point location = pictureBox1.Po开发者_JS百科intToScreen(e.Location);
  PopupForm form = new PopupForm(textBox, location, () => this.addToGrid(textBox.Text,e.Y)); 
  form.Show();
}


 private void addToGrid(String s,int loc)
 {
     DataGridViewRow row = new DataGridViewRow(); this.dataGridView1.Rows.Add(row);
     this.dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[0].Value = loc.ToString();
     this.dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[1].Value = s; 
 }


I think to resolve your problem you need to do something like this:

private void addToGrid(String s,int loc)
 {
     //create a new row
     DataGridViewRow row = new DataGridViewRow();

     //after initialize  values
     row.Cells[0].Value = loc.ToString();
     row.Cells[1].Value = s; 

     //add row to grid
     this.dataGridView1.Rows.Add(row);       
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜