c# - How to connect Tab Controls -


my winforms app has tab control consists of 2 tabs (tab1 & tab2). in tab2 data fetched in datagridview fron database(product infomations). in tab1, i've combobox [sales analyse]which makes user select option. want access tab2 tab1 on cb selection, displaying me regional sales information data in tab2 datagrid. possible? don't know wher start

tab1 image enter image description here

tab2

enter image description here expectation:

if combobox in tab1 selected, should through datagridview in tab2 (regions) north, east, west ect , sum sale 13, sales 14 .. , display in textboxes respectively.

as controls sit in 1 form methods can reference each other without additional help.

so can write in selectedindexchanged of combobox cbanalyse

cbanalyse_selectedindexchanged(object sender, eventargs e)  {     if (cbanalyse.selecteditem.tostringndex == "sales analysis"    {         sometextbox1.text = columnsum(yourdatagridview, somecolumn1) + "$";         sometextbox2.text = columnsum(yourdatagridview, somecolumn2) + "$";    } 

this uses small helper function, sums values 1 column in datagridview:

decimal columnsum(datagridview dgv, int columnindex) {     decimal sum = 0m;     (int row = 0; row < dgv.rows.count; row++)        if (dgv[columnindex, row].value != null) sum += convert.todecimal(dgv[1, row].value);     return sum; } 

folks run problems when need refer controls not sitting in either same form in 2nd, 3rd etc form. or when part of usercontrol, custome container holding controls.

in both cases controls default private members of other forms or of userobject.

in these cases 1 needs create kind of public accessor them, property. , in case of forms, 1 need provide reference other forms, stored when opening them.

in case, 2nd form needs back-refrence 1st form; pass in in constructor.

but in case none of these complications matter. need patience wire textboxes ;-)

update: seem have problem getting intermediate sums , need allow repeating regions in rows of tab 2, want use function calculate clause:

decimal columnsumwhere(datagridview dgv, int columnindex, string region) {     decimal sum = 0m;     (int row = 0; row < dgv.rows.count; row++)        if (dgv[columnindex, row].value != null) &&           (dgv[regioncolumn, row].value.tostring() == region)                sum += convert.todecimal(dgv[1, row].value);     return sum; } 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -