Hi
How can add row in DataGrid ?
Thanks
Printable View
Hi
How can add row in DataGrid ?
Thanks
Add a new record to your datasource.
no
i have 3 text in forn
text1 , text2, text3
How can add row in DataGrid ?
the data row from text do not save in databases only in form
Why are you using a Datagrid? If your data is coming from text boxes, why not just use the MSFlexGrid control?
To increase by one row in a Flesgrid the code would be...
Code:MSFlexgrid1.rows = MSFlexgrid1.rows + 1
hi
i use datagrid not MSFlexgrid
can i add row in DataGrid from text ?
datagrid only not MSFlexgrid
please help me
can that or no ?
please answer me
The DataGrid is bound to a recordset, as such in order for it to Add new rows you will need to add records to your database which will be reflected in the DataGrid.
The DataGrid requires an OLEDB Datasource such as an ADO Recordset. As Hack & dee-u pointed out, to add a new row to the DataGrid simply add a record to it's underlying Recordset.
You haven't indicated your requirements other than you don't want to use a database. Good news you don't need one. You can create and use an in-memory ADO Recordset. Add a Reference to the Microsoft ActiveX Data Object 2.X Library to your project.
Note that when the program is closed the data is lost. But it is simple enough to create a Save procedure to write the data to a text file or whatever your needs might be.Code:Private Sub Form_Load()
Dim rs As ADODB.Recordset
'Don't allow user to modify data in grid directly.
With DataGrid1
.AllowAddNew = False
.AllowDelete = False
.AllowUpdate = False
End With
'create an in-memory recordset with your required fields
Set rs = New ADODB.Recordset
rs.Fields.Append "LastName", adVarChar, 30
rs.Fields.Append "FirstName", adVarChar, 15
rs.Open
'bind recordset to Grid
Set DataGrid1.DataSource = rs
End Sub
Private Sub cmdAdd_Click()
Dim rs As ADODB.Recordset
'get the Grid's Recordset and add a new Record
Set rs = DataGrid1.DataSource
rs.AddNew Array("LastName", "FirstName"), Array(txtLastName.Text, txtFirstName.Text)
'you could use this syntax instead
'rs.AddNew
'rs.Fields("LastName").Value = txtLastName.text
'rs.Fields("FirstName").Value = txtFirstName.text
'ReBind the Grid so the new record is visible
DataGrid1.ReBind
End Sub
thanks for soultion my Error
How to make it save data into the actual database instead of having it save into an in-memory recordset?
Since it is an in-memory recordset, is there a way to save its data for next program session?