Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Application Gridview

Posted on 2009-07-16
5
Medium Priority
?
399 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

721 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