Solved

C# Application Gridview

Posted on 2009-07-16
5
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

631 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