473,379 Members | 1,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

datagrid entry with no db components

Hi,

How can I insert an entry to datagrid without using db components? For
example, I have a textbox and I would like to press OK button and
insert the text in textbox to datagrid.

Regards.

Feb 13 '06 #1
6 1105
Hi you need a datatable for that,
for example:

Dim dt As New DataTable("MyTable")
dt.Columns.Add("Name")
dt.Columns.Add("Country")
Datagrid1.DataSource = dt.DefaultView

you then can add rows with a datarow object or with

dt.LoadDataRow(New Object() _
{"Peter", "Belgium"}, True)
dt.LoadDataRow(New Object() _
{"Cor", "The Netherlands"}, True)
dt.LoadDataRow(New Object() _
{"Ken", "USA"}, True)
dt.LoadDataRow(New Object() _
{"You", Textbox1.Text}, True)

Hope this helps

Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

<mh******@gmail.com> schreef in bericht
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,

How can I insert an entry to datagrid without using db components? For
example, I have a textbox and I would like to press OK button and
insert the text in textbox to datagrid.

Regards.

Feb 13 '06 #2
Many thanks.

Feb 14 '06 #3
In addition how can I change the width of this columns I added?

Regards.

Feb 14 '06 #4
Hi, you can use a DataGridTableStyle and DataGridTextBoxColumn for that (see
code below)

Hope this helps

Greetz Peter

Dim dt As New DataTable("MyTable")
dt.Columns.Add("Name")
dt.Columns.Add("Country")
Dim ts1 As New DataGridTableStyle
ts1.MappingName = "MyTable" 'Has to be the same as the table name
Dim TextCol As DataGridTextBoxColumn
For i As Integer = 0 To dt.Columns.Count - 1
TextCol = New DataGridTextBoxColumn
Select Case i
Case 0
TextCol.Width = 50
TextCol.Alignment = HorizontalAlignment.Center
TextCol.HeaderText = dt.Columns(i).ColumnName
Case 1
TextCol.Width = 100
TextCol.Alignment = HorizontalAlignment.Center
TextCol.HeaderText = dt.Columns(i).ColumnName
TextCol.NullText = ""
End Select

TextCol.NullText = ""
TextCol.MappingName = dt.Columns(i).ColumnName
ts1.AllowSorting = False
ts1.GridColumnStyles.Add(TextCol)
Next

DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts1)

DataGrid1.DataSource = dt.DefaultView

dt.LoadDataRow(New Object() _
{"Peter", "Belgium"}, True)
dt.LoadDataRow(New Object() _
{"Cor", "The Netherlands"}, True)
dt.LoadDataRow(New Object() _
{"Ken", "USA"}, True)
dt.LoadDataRow(New Object() _
{"You", "Your Country"}, True)
Feb 14 '06 #5
Hi Peter,

Thanks for your time and helps.

Last question: Is it possible to use combobox on datagrid? For example
I want to add the values to be selected from the combobox manually.

Best Regards.

Feb 14 '06 #6
Hi have a look at these

http://www.vb-tips.com/default.aspx?...d-faf92f41f563

http://www.vb-tips.com/default.aspx?...9-3866d4936de0

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

<mh******@gmail.com> schreef in bericht
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi Peter,

Thanks for your time and helps.

Last question: Is it possible to use combobox on datagrid? For example
I want to add the values to be selected from the combobox manually.

Best Regards.

Feb 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: adove | last post by:
I am having problems with the following code. I am trying to update my db table Categories in Northwind. I have borrowed this code from www.dotnetjohn.com/articles/articleid27.aspx Although it...
14
by: Jack Kaufmann | last post by:
I am trying to verify a datagrid in which there must be an entry in both columns of any new row, and those values must be greater than the corresponding values in the previous row. It is pretty...
2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
4
by: - R | last post by:
Hello all. I'm new to .Net so please help me out. I have a application with several "Threads" running to observe various things. From time to time each thread need to add an log entry, which...
0
by: Mauro | last post by:
Hi, I need a big help to resolve this problem. I need to put a usercontrol in a datagrid: this control check if the code inserted is present in a archive and if not return a error message. (In...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
1
by: VanZandt | last post by:
I have a class(dll) that extends winform datagrid to provide link column in vb.net. I have managed to create a datagrid in c# winforms that shows link in one of the column but when I try to create a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.