/ / BindingSource a DataGridView predvolená aktuálna pozícia - c #, winforms, datagridview, bindingsource

BindingSource a DataGridView predvolená aktuálna pozícia - c #, winforms, datagridview, bindingsource

Má BindingSource automatické predvolené nastavenieAktuálna pozícia? Mám spracovateľa udalostí na udalosti CurrentCellChanged a zdá sa, že je to dvakrát. Programicky nastavím východiskovú pozíciu pomocou metódy BindingSource Find, ktorá funguje, ale predtým, než nastavím túto východiskovú pozíciu, CurrentCellChanged už spúšťa a počiatočnou vybratou bunkou je stĺpec 0 riadok 0. Keď vytvoríte BindingSource, už nastavuje Current nehnuteľnosť?

odpovede:

1 pre odpoveď č. 1

MSDN pre Vlastnosť DataGridView.CurrentCell spomína predvolenú hodnotu vlastnosti CurrentCell je prvá bunka v prvom riadku (alebo null, ak v DGV nie sú žiadne bunky).

Nastavenie tejto predvolenej hodnoty by spustilo vašu udalosť CurrentCellChanged a vysvetľuje, prečo uvidíte udalosť pre bunku 0, 0.


1 pre odpoveď č. 2

Som si úplne istý, čo vidíte, jeDataGridView spustil svoje rôzne výberové udalosti (CurrentCellChanged, SelectionChanged etc ...) počas procesu databinding. Pretože ste pripojili eventhandler k jednej z týchto udalostí, je to požiare.

Cesta okolo je pripojiť eventhandler DataGindingView DataGindingComplete DataGridView a pripojiť vaše CurrentCellChanged handler tam.

// Attach the event in the form"s constructor
this.dataGridView1.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView1_DataBindingComplete);

// And in the eventhandler, attach to the CurrentCellChanged event.
void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
dataGridView1.CurrentCellChanged += new EventHandler(dataGridView1_CurrentCellChanged);
}