How to make a DataGridViewComboBox column more reactive?

M

Massimo

I'm developing an application where there's a DataGridView and one of its
columns is of DataGridViewComboBox type. The combo box behaves as it should,
but I find it's a little too unfriendly to users, because of its very
lazy-looking behaviour.

I, as an user of the application, would like to click on the combo box, have
its pull-down menu... well, pull down :), select one item and watch the
application reacting to my input.

What actually happens is the following:

- I click on the combo box, but nothing happens if the grid wasn't already
the active control: this first click only moves the focus to it and/or
selects the row (I'm using the FullRowSelect selection mode here).
- If I click again on the combo box, or if the grid already had the focus,
no pull-down menu appears anyway, because this click only activates the cell
in the grid, without doing anything else.
- I then click *again*, quite disappointed, and now the control realizes
that someone is really yelling at it, so finally it wakes up and the menu
appears.
- I select an item, the menu disappears, but my event processing, which is
linked to the CellValueChanged event of the grid, doesn't start yet. I
suppose this is because at this point the cell is still in editing mode, so
its value actually didn't change.
- I then click anywhere on the grid, and now, at last, the cell becomes
inactive, its value changes, the event triggers and the application starts
doing its job.

I find this behaviour really annoying, and would like a way to make my
application's look&feel better.

In order to solve the last problem, I think I can link my processing to some
other event... but which one?

I really don't have any clue about removing the need for the first two
clicks, though :-(

Any help would be really appreciated.

Thanks


Massimo
 
T

Tim Van Wassenhove

Massimo schreef:
I, as an user of the application, would like to click on the combo box,
have its pull-down menu... well, pull down :), select one item and
watch the application reacting to my input.

I find that the DGV works nicer if i set the EditMode property to
EditOnEnter. In order to allow the user to select a fullrow i handle the
mouseclick event as following:

private void dataGridView1_MouseClick( object sender, MouseEventArgs e ) {
DataGridView.HitTestInfo hitInfo = this.dataGridView1.HitTest(e.X, e.Y);
if( hitInfo.Type == DataGridViewHitTestType.RowHeader ) {
this.dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
this.dataGridView1.EndEdit();
}
else
{
this.dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
}
}
 
M

Massimo

I find that the DGV works nicer if i set the EditMode property to
EditOnEnter.

It really does, thank you!
In order to allow the user to select a fullrow i handle the mouseclick
event as following:

Why is this needed?
I didn't use any of this code, and row selection works exactly the same as
it did before changing the EditMode.


Massimo
 
M

Massimo

I find that the DGV works nicer if i set the EditMode property to
EditOnEnter.

Addendum: any solution to the problem of having to click again after
modifying a ComboBox cell in order for the grid to fire a CellValueChanged
event?


Massimo
 
T

Tim Van Wassenhove

Massimo schreef:
Why is this needed?
I didn't use any of this code, and row selection works exactly the same
as it did before changing the EditMode.

Well, last time i tried it was impossible to select a row for deletion
with EditOnEnter.. Somehow i can't reproduce this problem anymore
though.. (Let's hope it's fixed now :))
 
T

Tim Van Wassenhove

Massimo schreef:
Addendum: any solution to the problem of having to click again after
modifying a ComboBox cell in order for the grid to fire a
CellValueChanged event?

The following code seems to work:

this.dataGridView1.EditingControlShowing +=
dataGridView1_EditingControlShowing;


void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
ComboBox comboBox = e.Control as ComboBox;
if (comboBox != null) {
// remove previously attached delegate
comboBox.SelectionChangeCommitted -= comboBox_SelectionChangeCommitted;

comboBox.SelectionChangeCommitted += comboBox_SelectionChangeCommitted;
}
}
}

void comboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
this.dataGridView1.EndEdit();
this.dataGridView1.CurrentCell.Value = ((ComboBox)sender).SelectedItem;
}
 
S

SIVAKKAMY MATHU

private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
// first remove event handler to keep from attaching multiple:
cb.SelectedIndexChanged -= new
EventHandler(cb_SelectedIndexChanged);

// now attach the event handler
cb.SelectedIndexChanged += new
EventHandler(cb_SelectedIndexChanged);
}
}

void cb_SelectedIndexChanged(object sender, EventArgs e)
{
// ----ADD CODES NEEDED TO ACEHIEVE THE TASK
}


EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top