I'm working on reading data from a spreadsheet and outputing it into a
datagridview in a windows form (.net 2.0). The problem I've found is that I'm
getting 84 rows where only one cell is populated, instead of 7 rows with with
12 cells populated. I think the problem is that I don't understand how to use
an ArrayList properly, or I need to use a more appropriate collection... but
then again it could be something completely different.
The key actions are these lines:
myList.Add(reco rd);
dgvSource.DataS ource = myList;
Could anyone give me some insight as to why my grid is not getting populated
correctly?
private void listWorksheets_ SelectedIndexCh anged(object sender, EventArgs e)
{
ArrayList myList = new ArrayList();
Int32 headerRow = 2;
dgvSource.DataS ource = "";
_sheet =
(Worksheet)_she ets.get_Item(li stWorksheets.Se lectedIndex + 1);
Object[,] saRet;
String valueString;
String myString = "";
for (int i = (headerRow + 1); i <= 10; i++)
{ // loop through 10 rows
Excel.Range range = _sheet.get_Rang e("A" + i.ToString(), "L"
+ i.ToString());
//Retrieve the data from the range.
saRet =
(System.Object[,])range.get_Valu e(System.Reflec tion.Missing.Va lue);
// another way to get the data that works also:
//System.Array myvalues = (System.Array)r ange.Cells.Valu e2;
//valueString = "Array Data\n";
for (int j = 1; j <= 12; j++)
{
//Write the next value into the string.
//valueString = String.Concat(v alueString, saRet[1,
j].ToString() + " | ");
MyItem record = new MyItem();
switch (j)
{
case 6:
record.typeCode = saRet[1, j].ToString();
break;
case 2:
record.acctNum = saRet[1, j].ToString();
break;
case 3:
//string
record.acctName = saRet[1, j].ToString();
break;
case 1:
record.dateOfRe port =
System.Convert. ToDateTime(saRe t[1, j].ToString());
break;
case 7:
record.postDate =
System.Convert. ToDateTime(saRe t[1, j].ToString());
break;
case 4:
record.effDate =
System.Convert. ToDateTime(saRe t[1, j].ToString());
break;
case 8:
record.beginBal ance = Decimal.Parse(s aRet[1,
j].ToString());
break;
case 9:
record.payment = Decimal.Parse(s aRet[1,
j].ToString());
break;
case 10:
record.origComm ission = Decimal.Parse(s aRet[1,
j].ToString());
break;
case 11:
record.calcComm ission = Decimal.Parse(s aRet[1,
j].ToString());
break;
case 12:
record.change = Decimal.Parse(s aRet[1,
j].ToString());
break;
default:
continue;
}
myList.Add(reco rd);
record = null;
}
//Write in a new line.
//valueString = String.Concat(v alueString, "\n");
//MessageBox.Show (valueString);
}
dgvSource.DataS ource = myList;
} 0 1186 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marc Gravell |
last post by:
I have a remote web-method that returns an array of strongly-typed objects;
on the client this gets a schema-based representation (as per wsdl.exe).
I have an array of (for instance) SearchResult objects; this has some simple
properties (which work fine), and some that are more complex - i.e. a
Customer property that is of type Person, which itself has properties Name
and Ref.
I want to bind a DataGridView to a List<SearchResult>; this...
|
by: Dave A |
last post by:
Hi,
I am struggling with two way databinding in WinForms and the DataGridView.
I am binding to business object classes (rather than datatables). If I
have a collection of these business objects that is the datasource of a
DataBinding that is bound to a DataGridView (WinForms) then I was expecting
that any change to the data would be reflected in the DataGridView (in other
words I was expecting the 2 way databinding to actually...
|
by: WayDownUnder |
last post by:
I have a datagridview that is bound to a cutom collection.
The classes contained in the custom collection have the properties that are
bound to the class . This works fine !
But if one of the properites exposes another object I would like to bind a
property of the sub object to the DataPropertyName this does not seem to
work.
eg main object customer
has a property called Address which is a contained object
inside object Address there...
|
by: michael sorens |
last post by:
I have generated an XmlDocument, then bound it to a DataGridView (thanks
to a pointer from PeterBromberg in a separate, recent posting). Now I want
to connect a BindingNavigator, but my rudimentary attempt failed.
In the Visual Designer I added a BindingSource bs, then a BindingNavigator
bn, and assigned bs to the BindingSource property of bn. In code, I
generate my XmlDocument, massage it to fit into a DataSet, then assign it
to the...
|
by: Tolgan |
last post by:
I have an object class "Person" say, with various public properties
including say "Name" and "Salary"
I have several person objects that I have created by some method outside the
scope of this discussion.
I want to setup a datagridview with each row corresponding to one person
object, and two columns being "Name" and "Salary". I want the user to be
able to click on the column heading to sort rows based on values in that
column. Users...
| |
by: Przemek M. Zawada |
last post by:
Dear Group,
I'm developing sample window form, using DataGridView control, which
is filled with data through BindingSource, which is based on type of
object, as follow:
public sampleClass
{
public int itemNumber;
public string itemName;
|
by: BenCoo |
last post by:
Hello everyone,
I'm programming in VB.NET 2005 and I habe not much experience with database
programming. I'm in search for some sql for the following :
I have 3 database tables: Movies, Theaters and a MovieProgram. Now I'm
|
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= |
last post by:
Hi,
I've a column in a dataGridView set as combobox. I can't find any example
showing how to populate the list in the combobox. Does anyone have an example
showing me this.
Regards Jesper.
|
by: Dennis Francek |
last post by:
Hello
I have populated a treeview from my dataset and by clicking in the treeview i want to get the corresponding table shown in a datagridview. Ive managed this by looking at each DataRow and child rows and added the nodes with a columnname from each datarow. At the same time i have put in a tag at each treenode with a filter string and the current table im looking at as a string to use for later so i can create a datatable and set a filter...
|
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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,...
|
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...
|
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, and deployment—without 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...
|
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...
|
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();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |