-
Dec 16th, 2008, 07:01 AM
#1
Thread Starter
Member
How can add row in DataGrid ?
Hi
How can add row in DataGrid ?
Thanks
-
Dec 16th, 2008, 07:18 AM
#2
Re: How can add row in DataGrid ?
Add a new record to your datasource.
-
Dec 16th, 2008, 07:26 AM
#3
Thread Starter
Member
Re: How can add row in DataGrid ?
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
-
Dec 16th, 2008, 09:50 AM
#4
Hyperactive Member
Re: How can add row in DataGrid ?
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
-
Dec 16th, 2008, 12:08 PM
#5
Thread Starter
Member
Re: How can add row in DataGrid ?
hi
i use datagrid not MSFlexgrid
can i add row in DataGrid from text ?
datagrid only not MSFlexgrid
please help me
-
Dec 17th, 2008, 06:34 AM
#6
Thread Starter
Member
Re: How can add row in DataGrid ?
can that or no ?
please answer me
-
Dec 17th, 2008, 07:21 AM
#7
Re: How can add row in DataGrid ?
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.
-
Dec 17th, 2008, 01:11 PM
#8
Re: How can add row in 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.
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
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.
-
Dec 19th, 2008, 10:28 PM
#9
Thread Starter
Member
Re: How can add row in DataGrid ?
thanks for soultion my Error
-
Aug 5th, 2020, 08:08 AM
#10
Junior Member
Re: How can add row in DataGrid ?
Originally Posted by brucevde
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.
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
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.
brucevde .. Yours is an example of a high-quality answer; most solutions on the internet are either half-mindedly put, too complicated, or are meant for off-showing purposes.
Thank you very much; you solved my problem.
-
Aug 6th, 2020, 05:58 PM
#11
Junior Member
Re: How can add row in DataGrid ?
How to make it save data into the actual database instead of having it save into an in-memory recordset?
-
Aug 7th, 2020, 06:44 PM
#12
Junior Member
Re: How can add row in DataGrid ?
Since it is an in-memory recordset, is there a way to save its data for next program session?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|