RowFocusChanged Event in datagrid?

I couldn’t find this event in dataGridview control, it seems in asp.net world they have a selectedIndexChanged event but winForm doesn’t. The closest one might be CurrentCellChanged, my translate code is:


        private int _currentRowIndex = -1;

        private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null) return;

            if (_currentRowIndex == dataGridView1.CurrentRow.Index) return;

            // I put my processing code in this method.
            dataGridRowChanged(sender, e);

            _currentRowIndex = dataGridView1.CurrentRow.Index;
        }

Which looks very stupid. To make it a little bit nicer, I can use Concurrency Manager instead.

 set {
                this.dataGridView1.DataSource = value;

                dataGridCurrentRowChanged(null, null);

                // Setup Concurrency Manager.
                dataGridView1.BindingContext[dataGridView1.DataSource]
                    .CurrentChanged += new EventHandler(dataGridCurrentRowChanged);

            }

Phew! UI coding is hard.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s