Tuesday, 15 January 2013

C# datagrid view wait for selected row -



C# datagrid view wait for selected row -

i have c# form function searches item in sql database, pops list of possible results in window. want wait until user selects row, homecoming result. works expected, can't come efficient way wait in loop until item selected. ideas?

function show window:

// sql crap fill dataset...// da.fill(items, "items"); connection.close(); var itemsearch = new window1(); // load new window datagrid itemsearch.show(); itemsearch.datagrid1.itemssource = items.tables["items"].defaultview; itemsearch.datagrid1.selectionmode = datagridselectionmode.single; itemsearch.datagrid1.selectionunit = datagridselectionunit.fullrow; while (itemsearch.datagrid1.selecteditem != null) { // until user selects row, homecoming row thread.sleep(100); // doesn't work... locks whole screen } } homecoming itemcode; // selected row

use itemsearch.showdialog . block subsequent code running until form closed.

and should set datagrid1 properties in form itself. pass datasource window1 constructor (you should overload default constructor) :

var itemsearch = new window1(items.tables["items"].defaultview); itemsearch.showdailog();

window1 constructor :

public window1(system.data.dataview datasource) { initializecomponent(); datagrid1.itemssource = datasource; datagrid1.selectionmode = datagridselectionmode.single; datagrid1.selectionunit = datagridselectionunit.fullrow; }

c# datagrid wait

No comments:

Post a Comment