473,467 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to assign array values to datagridview

28 New Member
hi,

how to assign a array as datasource to datagridview in vb.net.


my problem is

iam having an array with 60 values


For intVALUE_INDEX = 0 To (muiiobufCEMCON(intCEMCON).DIGITAL_INPUTS - 1
Dim intarray(mblnDIGITAL_INPUTS.Length) As Integer
Array.Copy(mblnDIGITAL_INPUTS, intarray, mblnDIGITAL_INPUTS.Length)

here in intarray iam having values


for displaying these values iam using a datagridview

here my requirement is iam displaying 16 values in each row

so i want to add 16 columns

here 60 values are there

so 60/16

4 rows

16 values -------- in 3 rows
another 12 values are ----------- in 4 th row

so how to dynamically creating rows and columns

so how it is possible

please any one give me reply

its very urgent

4 days iam wasting my time with this.but no solution


iam new to .net.please any one help me with code in vb.net.it is windows application
Oct 7 '08 #1
3 27888
mldisibio
190 Recognized Expert New Member
Your proposal is an incorrect use of a DataSource.

If the DataSource is a collection, then it represents a column in the DataGridView, and each item in the collection represents the row value for that column.

Since your array contains simple values, if you use it as a DataSource, it would represent one column. The DataGridView would display one columns with 60 int values.

If you require 16 columns you will have to manually add the columns to the Grid ColumnCollection. You will also have to manually add the rows to the RowCollection.

Then loop through your array and programatically set each cell value.

DataGridView[col, row].Value = myArray[i]

However, such a solution makes no use of the DataGridView or of data binding, or of any good programming practice.

To accomplish what you think DataBinding should do, you would create a class with 16 unique properties, and you would have an array of four instances of this object. Then when you bind to the array, it will create 16 columns, one for each property, and four rows, one for each object in the array. However, that is also a theoretical solution that makes no sense for what you are doing.

If you just want to display a list of integers spread out evenly, consider using a FlowLayoutPanel that wraps at 16 TextBoxes or Labels: How To Anchor and Dock Child Controls in a FlowLayoutPanel
Oct 7 '08 #2
vinidimple
2 New Member
Expand|Select|Wrap|Line Numbers
  1. EventLog eventlog = new EventLog();
  2.         string strWhichMachine = System.Net.Dns.GetHostName();
  3.         Hashtable ht;
  4.         DataSet ds = new DataSet();
  5.         DataTable dt = new DataTable();
  6.         DataRow drow;
  7. private void filllog()
  8.         {
  9.             DataColumn fIndex = new DataColumn();
  10.             dt.Columns.Add(fIndex);
  11.             DataColumn fMessage = new DataColumn();
  12.             dt.Columns.Add(fMessage);
  13.             DataColumn fSource = new DataColumn();
  14.             dt.Columns.Add(fSource);
  15.  
  16.             try
  17.             {
  18.                 eventlog.MachineName = strWhichMachine;
  19.                eventlog.Log = lbEventLogs.Items[lbEventLogs.SelectedIndex].ToString();
  20.                for (int i = 0; i < eventlog.Entries.Count; i++)
  21.                {
  22.                   // dgEventViewer[0, i].Value = eventlog.Entries[i];
  23.  
  24.                    drow = dt.NewRow();
  25.  
  26.                    fIndex.DataType = System.Type.GetType("System.String");
  27.                    fIndex.ColumnName = "Index";
  28.  
  29.                    fMessage.DataType = System.Type.GetType("System.String");
  30.                    fMessage.ColumnName = "Message";
  31.  
  32.                    fMessage.DataType = System.Type.GetType("System.String");
  33.                    fMessage.ColumnName = "Source";
  34.  
  35.                    drow[0] = eventlog.Entries[i].Index;
  36.                    drow[1] = eventlog.Entries[i].Message;
  37.                    drow[2] = eventlog.Entries[i].Source;
  38.                    dt.Rows.Add(drow);
  39.  
  40.                }
  41.                 dgEventViewer.DataSource=dt;                
  42.                 dgEventViewer.Refresh();
  43.  
  44.             }
  45.  protected void getlogfiles()
  46.         {
  47.             foreach (EventLog objEventLog in EventLog.GetEventLogs(strWhichMachine))
  48.             {
  49.                 lbEventLogs.Items.Add(new ListBoxItem(objEventLog.LogDisplayName, objEventLog.Log));
  50.                 lbEventLogs.SelectedIndex = 0;
  51.             }
  52.         }
Nov 27 '08 #3
DrLuiji
1 New Member
The above code works fine, it only need the catch after the DataGridView Refresh.
Many Thanks.
Dr.Luiji
Feb 10 '09 #4

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

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
26
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
7
by: Chris Wertman | last post by:
I am so lost on this one. Dim Ary as Integer = New Integer(4) {0,1,2,3} FAILS with the error: Array initializer has 1 too few elements. So I try Dim Ary as Integer = New Integer(3)...
6
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
9
by: active | last post by:
I need a control that displays a grid of rectangles. That is, like a brick wall except the rectangles are lined up. In VB6 I used such a control (may have been called FlexGrid but I'm not...
9
by: =?Utf-8?B?UGV0ZXJX?= | last post by:
I have a TabControl on a Windows form in which I have various tab pages each with a DataGridView, the first column of which is a DataGridViewCheckBoxColumn and subsequent columns being...
1
by: pbrown | last post by:
So I've got an array of string values which I'd like to display in an unbound DataGridView. What is the process necessary to simply load strings into cells of a datagrid? Ideally, we would go...
0
by: hydro123 | last post by:
I am using VC++2008 and am trying to read data enetered in unbound datagridview to implement in function. Under button_click event I entered the following: // initialize varaibles from...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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 project—planning, coding, testing,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.