winforms - Copy gridView rows -



winforms - Copy gridView rows -

how can re-create (devexpress) gridview rows other gridcontrol in form? write illustration please. kid form.

public partial class frmselectinvoice : devexpress.xtraeditors.xtraform{ public valinorentities valinor; public bindingsource src; public frmselectinvoice() { initializecomponent(); using (this.valinor = new valinorentities()) { this.valinor = new valinorentities(); this.src = new bindingsource(valinor.invoices_head, null); gridcontrol1.datasource = src; src.datasource = valinor.invoices_head; } } private void button1_click(object sender, eventargs e) { this.close(); }

}

i suffering same pain. able develop solution , works without problem. have provided basic code build own solution. can accomplish goal in 2 steps.

step1 : re-create grid-view row(s) clipboard [press ctrl+c]

step2 : paste clipboard info (or same) grid-view [press ctrl+v]

step 1: sample codes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

private void gridview1_keydown(object sender, keyeventargs e) { if (e.control && e.keycode == keys.c) { clipboard.settext(getselectedvalues(gridview1)); e.handled = true; } } private string getselectedvalues(devexpress.xtragrid.views.grid.gridview view) { //validate selected row count if (view.selectedrowscount == 0) homecoming ""; const string celldelimiter = "\t"; const string linedelimiter = "\r\n"; string result = ""; //iterate cells , compose tab delimited string of cell values (int = view.selectedrowscount - 1; >= 0; i--) { int row = view.getselectedrows()[i]; (int j = 0; j < view.visiblecolumns.count; j++) { result += view.getrowcelldisplaytext(row, view.visiblecolumns[j]); if (j != view.visiblecolumns.count - 1) result += celldelimiter; } if (i != 0) result += linedelimiter; } homecoming result; }

*now selected rows copied clipboard. so, can re-create these info excel or notepad if needed. tip: ms.excel format content smarter notepad.

step 2: sample codes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//for retrieving clipboard info string clipboarddata { { idataobject idata = clipboard.getdataobject(); if(idata == null) homecoming ""; if(idata.getdatapresent(dataformats.text)) homecoming (string)idata.getdata(dataformats.text); homecoming ""; } set { clipboard.setdataobject(value); } } datatable tbl; private void form1_load(object sender, system.eventargs e) { //create datatable data-source grid-control tbl = new datatable(); for(int = 0; < 3; i++) tbl.columns.add("column" + i.tostring()); for(int = 0; < 4; i++) tbl.rows.add(new object[] { "item" + i.tostring(), i, 3 - }); gridcontrol1.datasource = tbl; } //copy clip board infromation grid-view private void simplebutton1_click(object sender, system.eventargs e) { string[] info = clipboarddata.split('\n'); if(data.length < 1) return; foreach(string row in data) { addrow(row); } } void addrow(string data) { if(data == string.empty) return; string[] rowdata = data.split(new char[] { '\r', '\x09' }); datarow newrow = tbl.newrow(); for(int = 0; < rowdata.length; i++) { if(i >= tbl.columns.count) break; newrow[i] = rowdata[i]; } tbl.rows.add(newrow); }

additional codes : (if required) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if want provide functionality selecting multiple rows please utilize "multiselect" alternative shown in illustration below.

public fromload() { initializecomponent(); gridview1.optionsselection.multiselect = true; gridview1.optionsselection.multiselectmode = gridmultiselectmode.rowselect; gridview1.optionsbehavior.copytoclipboardwithcolumnheaders = true; }

please see next link more details on copytoclipboard method

https://documentation.devexpress.com/#windowsforms/devexpressxtragridviewsbasebaseview_copytoclipboardtopic

regards. kushan randima

winforms gridview devexpress

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -