473,696 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

displaying Array data in a Data Grid in VB.net

18 New Member
I'm trying to get an array to display in a data grid form in vb.net

The array has been imported from a csv, such that every array item is [date,time,flag] but I can split or join as needed to change the format of the array.

I want date, time, and flag to be seperate columns and each array item to be a new row.

I don't know where to start with this problem. I have looked through the msdn website and done some googling to no avail. If someone can point me to some better resources than I've been finding, it would be much appreciated.

Cheers
Mar 12 '08
16 12359
crusson
18 New Member
I moved on to different parts of the program hoping that when I came back to this problem I would magically think of a way to fix it...but I'm still having the same issues.

I am unable to size my columns to the width I want in the datagrid. I am able to resize all columns together, but not as seperate entities. I want column d to be really wide, but a,b,c can all be fairly small.

I am unable to figure this out. There is no .style or DefaultCellStyl e that I can access to change individual Columns. Can anyone throw me a few hints here?

Expand|Select|Wrap|Line Numbers
  1.     Private Sub displayArray()
  2.         'displays the array in the data grid form
  3.  
  4.         arrayMasterLen = terrarray.getDisplayArrayLen()     'the number of rows to be displayed
  5.         ReDim arrayMaster(arrayMasterLen)                   'dim the array it's stored to
  6.         arrayMaster = terrarray.getDisplayArray()           'store the array
  7.  
  8.         Dim dataTable1 As DataTable                         'new data table
  9.         dataTable1 = New DataTable("LineLog")
  10.         Try
  11.             Dim colA As DataColumn = New DataColumn("Date/Time")
  12.             colA.DataType = System.Type.GetType("System.String")
  13.             dataTable1.Columns.Add(colA)
  14.  
  15.  
  16.             Dim colB As DataColumn = New DataColumn("Flag")
  17.             colB.DataType = System.Type.GetType("System.String")
  18.             dataTable1.Columns.Add(colB)
  19.             Dim colC As DataColumn = New DataColumn("Code")
  20.             colC.DataType = System.Type.GetType("System.String")
  21.             dataTable1.Columns.Add(colC)
  22.             Dim colD As DataColumn = New DataColumn("Comments")
  23.             colD.DataType = System.Type.GetType("System.String")
  24.             dataTable1.Columns.Add(colD)
  25.  
  26.  
  27.             Dim j As Integer = 0
  28.             For j = 0 To arrayMasterLen - 1
  29.                 Dim row As DataRow
  30.                 row = dataTable1.NewRow()
  31.                 row.Item("Date/Time") = terrarray.returnDateEntry(j)
  32.                 row.Item("Flag") = terrarray.returnFlag(j)
  33.                 row.Item("Code") = terrarray.returnCode(j)
  34.                 row.Item("Comments") = terrarray.returnComment(j)
  35.                 dataTable1.Rows.Add(row)
  36.             Next
  37.         Catch
  38.         End Try
  39.  
  40.         DataGrid1.PreferredColumnWidth() = 120
  41.         DataGrid1.DataSource = dataTable1
  42.         DataGrid1.RowHeadersVisible = True
  43.         DataGrid1.Name = "LineEntries"
  44.         DataGrid1.Refresh()
  45.  
  46.     End Sub
Mar 25 '08 #11
Plater
7,872 Recognized Expert Expert
Hmm, while there does not seem to be any width parameter, all DataGridViewCol umns have that style element I was talking about.
(There's two, one for the header cell and one for the regular cells)

There is also the auto-size mode, which might do what you want it to do?

Hmm, this IS a windows application right and not for a webapplication?
Mar 25 '08 #12
crusson
18 New Member
Thanks for replying. I feel like kind of a moron, but I'm still unable to figure this out. This is a windows app, not a web app. I think part of my problem is that I cannot figure out how to refer to the columns of the actual data grid. I can refer to columns of the data table, but cannot do anything with them width-wise. I think it may be that I'm applying a data table to be the data source of the data grid and cannot refer to those columns once they've been added to the data grid. Is there any way to refer to these columns in the datagrid?

I am able to set the preferred width of the datagrid (which applies to all columns in the table) but cannot find the auto-size mode you speak of. Should it appear in my properties window and doesn't? Or should I need to code it after adding the data to the datagrid. If it just automatically sizes every column to its widest width, that would be perfect.

Hmm, while there does not seem to be any width parameter, all DataGridViewCol umns have that style element I was talking about.
(There's two, one for the header cell and one for the regular cells)

There is also the auto-size mode, which might do what you want it to do?

Hmm, this IS a windows application right and not for a webapplication?
Mar 25 '08 #13
Plater
7,872 Recognized Expert Expert
Hmm you are using DataGrid object and not a DataGridView object then? That will be trickier then, I am unfamiliar with the vs2003 version of the object.
Mar 25 '08 #14
crusson
18 New Member
Yes, I am using a datagrid object, not a datagridview object. I've never used one of these objects before this project, so I have no real idea how they work. I know that generally they are used with databases instead of arrays. Would a database as an intermediary step be a necessary middleman?
Mar 25 '08 #15
Plater
7,872 Recognized Expert Expert
If you are using a newer then VS2003, save yourself a lot of headache and switch to a DataGridView.
Mar 25 '08 #16
crusson
18 New Member
Sadly it appears that I'm using vs2001. I guess I need to try some completely different work-around...
Mar 25 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1181
by: Mike | last post by:
I'm creating a asp.net application in C#. (i'm new to this process). All the examples i see that are displaying data are using the DataGridControl. Can anyone point me to some examples that is displaying data from a SQL database without using the DataGrid? Thx
7
269
by: C Newby | last post by:
I have a data grid control taht contains a data bound coulmn called "Type". Depending on the value of "Type" I want to display a corresponding image in the rendered table cell. So, if the value of type is 1, I want to show image1.gif. If the value is 2, I want to show image2.gif. Is there an easy way to do this? TIA//
1
2671
by: Anthony | last post by:
I am defining the datagridtable style for a grid .... Dim coursekeycol As New DataGridTextBoxColumn coursekeycol.MappingName = COURSEKEYCOLNAME coursekeycol.HeaderText = "" coursekeycol.Width = COURSEKEYCOLWIDTH .... I am wondering, how to I set the cells so that the user
14
4397
by: Susan Rice | last post by:
I want to create a readonly array of data, then a readonly array of a structure. This is data I access but I want it protected against accidental change. The following is my test code. #include "stdafx.h" struct LVC { unsigned short int lo; unsigned short int hi;
4
4534
by: daqmaneng | last post by:
does anyone have any suggestions for writing a two dimensional array of data to a file. Currently, I have an array of 5 columns, with 1000 elements per array. I know that I can use a for next loop to go through each data point in the array and use the streamwriter class for each individual data point and write each point individually to the file. I would like to simplify this by simply writing the entire array to file.
15
8434
by: Madhur | last post by:
Hi All, I would like you help me in creating an array of data types. I am interested in look at the the data type which looks like this Array a={int,float,char,int*..............................}, so that a should return me int and a should return me
3
1498
by: makis | last post by:
hello, How can i send data from grid component to messagebox? which code or process we need?
0
997
blossam
by: blossam | last post by:
hi friends, i want to add data in grid at runtime means when i click enter or tab i want a new row in grid so i can add value in that i know how to do this in windows application but i want to do this in web application please help me if you know i dont want to create row by using TableRow =new TableRow() and add it to table
5
10046
by: billelev | last post by:
I have a large array of data (1000 x 40 x 3) that I am inserting into a database table. It is incredibly slow, and so I was wondering if there is a quicker way of inserting array data into a table. Here is the code I am currently using: ' ,, With rs For nSec = 0 To UBound(vtData, 2) For ndate = 0 To UBound(vtData, 1) For nfield = 1 To UBound(vtData, 3)
0
9145
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
9010
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...
1
8880
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8853
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6515
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
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4356
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...
2
2319
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1992
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.