c# - Displaying Checked column Values in Datagridview checkbox showing data in another form Datagridview -
i have 1 datagridview(datagridview1
contains datagridview2
column header) in have 1 checkboxcolumn, called dgvckb
, in datagridview1
. when uncheck dgvckb
in row data of row should not shown in datagridview2
(datagridview2
connected database(localhost)).
1st form datagridview is:
2nd form datagridview is:
my coding this:
form1 coding
private void customized_column_load(object sender, eventargs e) { datagridview1.columncount = 2; datagridviewcheckboxcolumn dgvckb = new datagridviewcheckboxcolumn(); dgvckb.valuetype = typeof(bool); dgvckb.name = "chk"; dgvckb.headertext = "vis."; datagridview1.columns.add(dgvckb); datagridview1.columns[0].name = "column"; datagridview1.columns[1].name = "column size"; string[] row = new string[] {"date", "103" }; datagridview1.rows.add(row); row = new string[] {"time", "103" }; datagridview1.rows.add(row); row = new string[] { "callee number", "103" }; datagridview1.rows.add(row); row = new string[] { "user", "103" }; datagridview1.rows.add(row); row = new string[] { "called number", "103" }; datagridview1.rows.add(row); row = new string[] { "department", "103" }; datagridview1.rows.add(row); row = new string[] { "trunk", "103" }; datagridview1.rows.add(row); row = new string[] { "city", "103" }; datagridview1.rows.add(row); row = new string[] { "duration", "103" }; datagridview1.rows.add(row); row = new string[] { "pulse", "103" }; datagridview1.rows.add(row); row = new string[] { "amount", "103" }; datagridview1.rows.add(row); row = new string[] { "status", "103" }; datagridview1.rows.add(row); row = new string[] { "callee extension", "103" }; datagridview1.rows.add(row); row = new string[] { "trunk port", "103" }; datagridview1.rows.add(row); row = new string[] { "call type", "103" }; datagridview1.rows.add(row); }
form2 coding
string myconstring = "server=localhost;" + "database=test;" + "uid=root;" + "password=asterisk"; private void pbx_logger_load(object sender, eventargs e) { mysqlconnection con = new mysqlconnection(myconstring); mysqlcommand cmd = new mysqlcommand("select date date,time time,user user,department department,trunk trunk,city city,calleenumber calleenumber,callednumber callednumber,duration duration,pulse pulse,amount amount,status status,calleextension calleeextension,trunkport trunkport,calltype calltype pbx", con); con.open(); datatable datatable = new datatable(); mysqldataadapter da = new mysqldataadapter(cmd); da.fill(datatable); datagridview1.datasource = datatable; }
i new development looking solution. please refer me link.
thank you
regards dhana
for simplicity, let's assume form names based on load
method handles match accordingly:
form1.load += customized_column_load; form2.load += pbx_logger_load;
i have assumed opening second form form1
follows:
form2 form2 = new form2(); form2.showdialog();
as such, second form needs access first form's grid values. if pass in datagridview
form2
constructor, form2
can save variable , recall during load time - rows can looped through , size , visibility values accessed , used on second form's datagridview
:
private datagridview parentdgv; public form2(datagridview parentdgv) { initializecomponent(); this.parentdgv = parentdgv; } private void pbx_logger_load(object sender, eventargs e) { datagridview1.allowusertoaddrows = false; // code fill datasource. foreach (datagridviewrow row in parentdgv.rows) { string colname = row.cells["column"].value.tostring(); int size = 0; int.tryparse(row.cells["column size"].value.tostring(), out size); datagridview1.columns[colname].width = size; datagridview1.columns[colname].visible = row.cells["chk"].value != null && (bool)row.cells["chk"].value; } }
lastly, in form1
, change call accordingly:
form2 form2 = new form2(datagridview1); form2.showdialog();
this assumes following set in form1
too:
datagridview1.allowusertoaddrows = false;
otherwise you'll need add null checks when looping through rows inside form2
.
Comments
Post a Comment