Solved

C# Application Gridview

Posted on 2009-07-16
5
380 Views
Last Modified: 2012-05-07
Greetings all,

I am currently running an SQL command to generate a gridview from an excel file.  This works fine, but what I want to do is to generate another gridview from the first which will be customized with headers etc..

I need the first one because the users might want to change something and see how it affects the others, a date for example.  

I currently have the code listed below to get the data, and that works fine.

I then have a datatable, which will eventually be a filtered view of the datagrid, as follows
            DataTable aTable = new DataTable("A");
            DataColumn dtCol;
            DataRow dtRow;
            // Create ID column and add to the DataTable.
            dtCol = new DataColumn();
            dtCol.DataType= System.Type.GetType("System.Int32");
            dtCol.ColumnName = "ID";
            dtCol.AutoIncrement = true;
            dtCol.Caption = "ID";
            dtCol.ReadOnly = true;
            dtCol.Unique = true;
            // Add the column to the DataColumnCollection.
            aTable.Columns.Add(dtCol);
            // Create Name column and add to the table
            dtCol = new DataColumn();
            dtCol.DataType= System.Type.GetType("System.String");
            dtCol.ColumnName = "FName";
            dtCol.AutoIncrement = false;
            dtCol.Caption = "First Name";
            dtCol.ReadOnly = false;
            dtCol.Unique = false;
            aTable.Columns.Add(dtCol);

            aTable.Rows.Add(dtRow);


for the sake of use, I copied something off the web, imagine that.

What I need to do is to merge 2 fields horizontally and vertically for header information, kind of lke a matrix of information.

Second, maybe a different question, but I need to copy a filtered view of the datagrid from the source to the datatable.

Thanks in advance for the help.


SourceGrid.DataSource = null;

            

            String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +

            "Data Source=" + txtSource.Text + 

            ";Extended Properties=Excel 8.0;";

            OleDbConnection conn = new OleDbConnection(strConn);

            OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * from [Sheet1$] Where [Name] like '%name_parameter%'", conn);

            DataSet myDataSet = new DataSet();

            myCommand.Fill(myDataSet);

            conn.Close();
 

            SourceGrid.DataSource = myDataSet.Tables[0];

Open in new window

0
Comment
Question by:rg20
  • 2
  • 2
5 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 24876832
Is this windows or web?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24878232
Great question, because without GridView.DataBind(), nothing is going to work, so I would guess Windows Forms application...
0
 
LVL 9

Author Comment

by:rg20
ID: 24878544
Yes this is a Windows application NOT a web app.
0
 
LVL 9

Author Comment

by:rg20
ID: 24878591
I am not interested in binding the data to the Excel sheet as that is a one time load into the system, but I am interested in binding the datagrids together in a later stage so if the main grid changes, all the others can be reflected.

Grid 1
department  Project       date

grid 2
                           DATE          DATE
DEPARTMENT   project1       Project3
                         project2

department

As you might be able to tell,  I am looking to see if a project is in the planning stage, or development stage based on the milestone date and the current date.  

When they change a milestone date in the main grid, I am going to update the other grid based on that.
I could use a piviot, but it has to have date logic.  But thats later and I am not asking for someone to write it for me.

I just never merged rows before in a datagrid and am new to c# windows stuff, web would be easier.

Thanks again
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 24879821
DataGridView doesn't support cell merging, you have to pull off a lot of strings to do something nice off of it.

I leave you some threads you can use:
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/fea3dcff-5447-450a-8f7c-bb1c4f63371d
http://www.codeguru.com/forum/showthread.php?t=415930
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now