c# - How to write every time to a new row of data table? -
How do I insert a separate row into a datrator each time? The data table is used to write a data in the DataGrid view. I need every time, which needs to be written in a different row (row) in the data, when I do not know how many rows should be required in runtime. talk; The data is loaded with an XML file, so data tables can already have rows.
What can I do? (In short, I always write in the same line) Edit in C #: Here is the code:
For some reason, DateGridView is only one line (this is a Method which is active in one click of a button)
public zero gridstart (string i, string b, string c) {datatabase dt = new datatable (); // empty table without schema DataColumn colContactID = new data column ("date", typef (string)); DatacolumncolContactName = new data column ("collar", typef (string)); Data column collarsalt = new data column ("result", typef (string)); Dt.Columns.Add (colContactID); Dt.Columns.Add (colContactName); Dt.Columns.Add (colResult); Datarao Row = DT NRO (); Line ["date"] = i; Row ["collar"] = b; Line ["result"] = c; Dt.Rows.Add (line); }
You should be able to use There are many samples on that MSDN page. If you have more questions, please provide some sample code in your reply.
Private Zero Form 1_load (Object Sender, EventArgs e) {dataGridView1.DataSource = MyDataTable; } Private string _fileName = "MyCache.xml"; Private dataTable _modetable; Public DataTable MyDataTable {get {if (_myDataTable == empty) {_myDataTable = New DataTable (); If (file example (_fileName)) _myDataTable.ReadXml (_fileName); Other InitDataTable (_myDataTable); } Back _myDataTable; }} Private Zero InitDataTable (DataTable Table) {table.TableName = "MyTable"; Table. Columns Add ("Date", Typef (DateTime)); Table Columns Add ("collar", typef (string)); Table Columns Add ("result", typef (string)); } // Call your Ad Code this method! Private Zero AddValue (date time date, string collar, string result) {var row = MyDataTable.NewRow (); Line ["date"] = date; Row ["collar"] = collar; Line ["result"] = results; MyDataTable.Rows.Add (line); } Secure override zero onclosed (eventArgS E) {if (_myDataTable! = Null) _myDataTable.WriteXml (_fileName, XmlWriteMode.WriteSchema); Base.OnClosed (E); }
Comments
Post a Comment