473,830 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1123
Hi you need a datatable for that,
for example:

Dim dt As New DataTable("MyTa ble")
dt.Columns.Add( "Name")
dt.Columns.Add( "Country")
Datagrid1.DataS ource = 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.goo glegroups.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 DataGridTableSt yle and DataGridTextBox Column for that (see
code below)

Hope this helps

Greetz Peter

Dim dt As New DataTable("MyTa ble")
dt.Columns.Add( "Name")
dt.Columns.Add( "Country")
Dim ts1 As New DataGridTableSt yle
ts1.MappingName = "MyTable" 'Has to be the same as the table name
Dim TextCol As DataGridTextBox Column
For i As Integer = 0 To dt.Columns.Coun t - 1
TextCol = New DataGridTextBox Column
Select Case i
Case 0
TextCol.Width = 50
TextCol.Alignme nt = HorizontalAlign ment.Center
TextCol.HeaderT ext = dt.Columns(i).C olumnName
Case 1
TextCol.Width = 100
TextCol.Alignme nt = HorizontalAlign ment.Center
TextCol.HeaderT ext = dt.Columns(i).C olumnName
TextCol.NullTex t = ""
End Select

TextCol.NullTex t = ""
TextCol.Mapping Name = dt.Columns(i).C olumnName
ts1.AllowSortin g = False
ts1.GridColumnS tyles.Add(TextC ol)
Next

DataGrid1.Table Styles.Clear()
DataGrid1.Table Styles.Add(ts1)

DataGrid1.DataS ource = 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.goo glegroups.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
432
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 works on dotnetjohn website, I cannot replicate the code successfully. I have a datagrid filled with data and two textboxes with an “Insert” button. When the button is pressed, the text entered into the two textboxes is to be added to the table...
14
2111
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 simple to verify the cell the user starts in by invoking a verifying event for the underlying textbox in that cell, but what I would like to do is to change the focus to the other column in the new row if it has not been filled in. If in handling...
2
3280
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 use the F2 key to enter edit mode and then hit TAB or ESCAPE without actually editing the value, dotnet crashes with a null reference error.
2
2772
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. The problem is the article is in VisualBasic. I already get the collection to be recognized as a Data Source by the IDE. It populated the DataGrid correctly from the fields on the items object of the collection, but I can't get the DataGrid to...
3
10424
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== using System; using System.Drawing; using System.Collections; using System.ComponentModel;
4
1566
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 is displayed on a form (a datagrid on a form) there is no database, but i created a dataset using the designer. One Entity/Table is called Log and contains the log-entries.
0
3554
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 the example I have changed this check with a easy "if string is empty" ) Everything would be easy if the datagrid had a predictable behaviour. I explain my problem.
3
4269
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 of a subclassed DataGridTextBoxColum dos not seem like a practical way to do it. I have subclassed a DataGrid and overridden the OnPaint as such:
1
1530
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 EventHandler I get a compilation error: "Method 'DataGridLink.Form1.cs_LinkClicked does not match delegate" can anyone please help? Thanks for all the help. here is my code: using System; using System.Drawing; using System.Collections;
0
9780
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9641
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10769
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10476
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5615
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3070
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.