Dynamically Add a dview

Source: Internet
Author: User

// Load XML data
Private void buttonx#click (Object sender, eventargs E)
{
// Read XML
// Builddatagrid (getobjectarraylist (@ "E: \ tddownload \ design mode \ abstractfactory \ objectidentity \ XML \"), this. tabcontrolpanel1 );
// Builddatagrid (getobjectarraylist (@ "E: \ tddownload \ design mode \ abstractfactory \ objectidentity \ XML \"), this. tabcontrolpanel2 );
Builddatagrid (getobjectarraylist (@ "E: \ tddownload \ design mode \ abstractfactory \ objectidentity \ XML \ Canyonlands. xml"), this. tabcontrolpanel3 );
// Builddatagrid (getobjectarraylist (@ "E: \ tddownload \ design mode \ abstractfactory \ objectidentity \ XML \"), this. tabcontrolpanel4 );
// Builddatagrid (getobjectarraylist (@ "E: \ tddownload \ design mode \ abstractfactory \ objectidentity \ XML \"), this. tabcontrolpanel5 );

builddatagrid (getobjectarraylist (@ "E: \ tddownload \ Design Pattern \ abstractfactory \ objectidentity \ XML \ water. XML "), this. tabcontrolpanel6);
// builddatagrid (getobjectarraylist (@ "E: \ tddownload \ design mode \ abstractfactory \ objectidentity \ XML \"), this. tabcontrolpanel7);
// builddatagrid (getobjectarraylist (@ "E: \ tddownload \ design mode \ abstractfactory \ objectidentity \ XML \"), this. tabcontrolpanel8);
builddatagrid (getobjectarraylist (@ "E: \ tddownload \ design mode \ abstractfactory \ objectidentity \ XML \ building. XML "), this. tabcontrolpanel9);
}

///


// return an array from XML
///
///
//
protected list getobjectarraylist (string filepath)
{

Xmldatadocument Doc = new xmldatadocument ();
Doc. Load (filepath );
List <string []> arrlist = new list <string []> ();
If (Doc! = NULL)
{
Xmlnodelist nodelist = xmlopre. findnodelistbyname ("object", Doc. selectsinglenode ("objectlist "));

Foreach (xmlnode node in nodelist)
{
String [] result = {
(Node. selectsinglenode ("symbol"). innertext + "" + node. selectsinglenode ("no"). innertext ),
Node. selectsinglenode ("objectid"). innertext,
Node. selectsinglenode ("objectname"). innertext,
Node. selectsinglenode ("objecttype"). innertext
};
Arrlist. Add (result );
// This. Maid. Add (result, tabcontrolpanel3 );
}
}
Return arrlist;
}

/// <Summary>
/// Input an array to dynamically generate the datagridview
/// </Summary>
/// <Param name = "arrlist"> </param>
/// <Param name = "tbpanel"> </param>
Protected void builddatagrid (list <string []> arrlist, devcomponents. dotnetbar. tabcontrolpanel tbpanel)
{
Devcomponents. dotnetbar. Controls. datagridviewx DataGrid = new devcomponents. dotnetbar. Controls. datagridviewx ();
System. Windows. Forms. Maid ();;
System. Windows. Forms. Maid ();;
System. Windows. Forms. Maid ();;
System. Windows. Forms. Maid ();

Symbol. defaultcellstyle. Alignment = maid. bottomright;
Symbol. datapropertyname = "symbol ";
Symbol. headertext = "no ";
Symbol. width = 50;
Symbol. readonly = true;

Objectid. datapropertyname = "objectid ";
Objectid. headertext = "**";
Objectid. width = 50;
Objectid. readonly = true;

Objectname. datapropertyname = "objectname ";
Objectname. headertext = "name ";
Objectname. width = 80;
Objectname. readonly = true;

Objecttype. datapropertyname = "objectname ";
Objecttype. headertext = "type ";
Objecttype. width = 80;
Objecttype. readonly = true;

DataGrid. autogeneratecolumns = false;
DataGrid. Dock = tbpanel. Dock;
DataGrid. Columns. Add (Symbol );
DataGrid. Columns. Add (objectid );
DataGrid. Columns. Add (objectname );
DataGrid. Columns. Add (objecttype );
DataGrid. rowheadersvisible = false;
DataGrid. cellcontentdoubleclick + = new maid (maid );
Foreach (string [] result in arrlist)
{
DataGrid. Rows. Add (result );
}
Tbpanel. Controls. Add (DataGrid );

}

///


// datagridview
///
///
//
void datagrid_cellcontentdoubleclick (Object sender, datagridviewcelleventargs e)
{< br> devcomponents. dotnetbar. controls. datagridviewx DataGrid = (devcomponents. dotnetbar. controls. datagridviewx) sender;

String symbol = DataGrid. Rows [E. rowindex]. cells [0]. value. tostring ();
String objectname = DataGrid. Rows [E. rowindex]. cells [1]. value. tostring ();
String objecttype = DataGrid. Rows [E. rowindex]. cells [2]. value. tostring ();
MessageBox. Show (symbol + "" + objectname + "" + objecttype );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.