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
Solved

C# Application Gridview

Posted on 2009-07-16
5
385 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

837 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