Solved

C# Application Gridview

Posted on 2009-07-16
5
378 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
Comment Utility
Is this windows or web?
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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
Comment Utility
Yes this is a Windows application NOT a web app.
0
 
LVL 9

Author Comment

by:rg20
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

16 Experts available now in Live!

Get 1:1 Help Now