views:

326

answers:

3

I created a custom DataGridViewCell to show a specific UserControl when the user starts editing the cell. Basically the control contains a TextBox with a suggestion list easily handled by the code.
I got my code to resize the list correctly, and have it contain exactly what I want and where I want it. The problem I have now is that the control is not being drawn correctly on the screen, and the ListBox is probably beind drawn "inside" the row, and since it is much higher than the row, does not get shown on screen.

How can I make the control draw on top of the DataGridView?

+2  A: 

You'll probably need to put the ListBox in a separate popup form. Good luck.

Alternatively, you can put the ListBox in the GridView's parent form, then call BringToTop to make sure it's on top of the grid view.

SLaks
A: 

There's a msdn article, Build a Custom NumericUpDown Cell and Column for the DataGridView Control, that paints custom controls on datagridviews. The code sample provided there might help solve your problem.

hjb417
No, it won't help solve his problem.
SLaks
A: 

I think you'll want to take a look at Faking alternative controls within a DataGridView control in Win Forms 2.0. It will look like the control is hosted within the DataGridView, but in actuality it is just positioned nicely over the cell. I am using this now for two DateTimePickers and one ComboBox with great success.

Sample code from link:

protected void dgCategory_CellClick(object sender, DataGridViewCellEventArgs e)

{

//set Date Picker to false when initially click on cell

      if (dtPicker.Visible)
          dtPicker.Visible = false;
      if (e.ColumnIndex == 2)
      {
      //set date picker for category datagrid
         dtPicker.Size = dgCategory.CurrentCell.Size;
         dtPicker.Top = dgCategory.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Top;
         dtPicker.Left = dgCategory.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Left;

         if (!(object.Equals(Convert.ToString(dgCategory.CurrentCell.Value), "")))
             dtPicker.Value = Convert.ToDateTime(dgCategory.CurrentCell.Value);
         dtPicker.Visible = true;

      }
}

private void dtPicker_ValueChanged(object sender, EventArgs e)
{
      dgCategory.CurrentCell.Value = dtPicker.Value;
      dtPicker.Visible = false;

}
0A0D