FlexGrid / Datagrid question

Hi,

I know that there is no Flexgrid in VB.NET 2003, and most posts I have seen are directing people to the datagrid. My problem is that I don't think the datagrid is an option in my case.

I have recently upgraded my VB6 app to VB.NET 2003, which uses a FlexGrid.

I populate the grid at runtime...and NOT from a database table

The grid uses column AND row headings, which I need to be fixed in place...ie when the user scrolls horizontally or vertically, the first row and the first column must always be visible.

Here is an example of what I need, but imagine the grid being 40 cols by 300 rows:

Hours Days Years Something....
-----------------------------
Jason |1 |2 |5 |2
Frank |16 |32 |1 |2
Stephen |2 |4 |2 |5
Lisa |4 |3 |44 |1

I have played with the datagrid and I just can't seem to figure out how to get it working for my needs.

Can any one point me to a "howto" page please if you know that what I'm trying to do is possible with the datagrid.

Alternatively, if there is another standard control I could use would be great. I read a post earlier point someone to a TableLayoutPanel:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=136757&SiteID=1

Apparently this comes with .NET 2.0

Now, I downloaded and installed the redist for .NET 2.0 and either I did something wrong or I haven't understood something, but either way, this control does not exist for me. Also, from the VB.NET IDE, when I click Help-->About, it tells me I only have .NET 1.1

Thanks in advance for any assistance.

MJ



Answer this question

FlexGrid / Datagrid question

  • Chris Mayo - MSFT

    Wow! Thanks for the link. I haven't looked in great detail as yet, but what I have seen looks great. Thanks a lot, I really appreciate it.

    MJ


  • Scott Stalter 1

    using System;     < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    using System.Data;

    using System.Windows.Forms;

     

     

    public sealed class MyTableStyle : DataGridTableStyle

    {

        public MyTableStyle()

        {

     

            this.MappingName = "MySchedule";

            this.ReadOnly = true;

     

            DataGridTextBoxColumn Hour1Col = new DataGridTextBoxColumn();

            Hour1Col.MappingName = "1";

            Hour1Col.HeaderText = "1";

            Hour1Col.Width = 100;

            this.GridColumnStyles.Add(Hour1Col);

     

            //...

     

            DataGridTextBoxColumn Hour13Col = new DataGridTextBoxColumn();

            Hour1Col.MappingName = "13";

            Hour1Col.HeaderText = "1";

            Hour1Col.Width = 100;

            this.GridColumnStyles.Add(Hour1Col);

     

            //...

     

            //Add other columns

     

        }

     

    }

     

    public sealed class MyClass

    {

        DataTable ScheduleTable;

     

        public void DisplaySechedule()

        {

            ScheduleTable = new DataTable("MySchedule");

            ScheduleTable.Columns.Add("1");

            //AddColumns through to 24.  Add other columns

     

            //Iterate through your database data and populate the ScheduleTable

            foreach (Driver CurrentDriver in DriverCollection)

            {

                DataRow NewRow = ScheduleTable.NewRow();

                //..... 

                ScheduleTable.Rows.Add(NewRow);

            }

           

            MyDataGrid.TableStyles.Add(new MyTableStyle());

            MyDataGrid.DataSource = ScheduleTable;

     

        }

    }

     


  • Varied Interest

    Oh yeah, one more thing...

    I also want to be able to individually set each column to a width of my specification...

    Each columns width will be different.


  • _Prabhu Sadasivam

    Following on from my previous posts, my requirements are for a grid that is NOT bound to any database table as it has no relationship to any database.

    It seems that this datagrid has been developed with the assumption that the only time we need a grid control is for viewing/modifying database tables. It has been a royal pain in the butt trying to impliment this control for my needs. I really wanted to populate the grid on a cell by cell basis...this is not the same as a row by row basis.

    Another problem has just arisen where in my grid, I have around 30 or so columns at any one time. The problem is that I set the "Headings" for each column based on information supplied by the user, so it is VERY possible to have 2 or more columns needing the same heading text...an example would be columns with the heading being the first name of each person in a class room. There would be a high probability of more than one "Dave" in the class. It seems the datagrid doesn't allow this.

    ...or does it Can anyone offer some advice on how to overcome this please.

    Dial, I read your datagrid FAQ page and couldn't find anything related to this...at least, I hope I didn't miss something. I read the list of questions twice.

    Thanks in advance

    MJ


  • Rep

    Hi Dial,

    Thanks for following my post.

    Yes, you're right that a dynamic solution is required. One of the apps I'm converting from VB6 is a daily schedule screen. It's used by someone to quickly mark the days schedule and then print it off. There is no requirement to store the information after this. (I have written code to store the info into an Access database though, they just don't use it).

    Down the left hand side they list the First names of individuals from a company's workshop floor. This is how they like to operate...ie they don't want to put the persons last name.

    Along the top, they list the time, in hours, for a 24 hour period...however, they do not want AM or PM, nor do they want a 24 hour format...ie you get from 1 to 12 twice. They also have 10 other columns used for non-schedule related information...such as Who's on call, who's driving the busses etc.

    They are not able to edit any of the cells. I supply the column header text. The names of the people come from a database, but that's it. When they want to schedule "Dave" in from 1 until 4, they simply click and hold the left mouse on the cell corresponding to "Dave at 1", then drag right high-lighting the cells as they go until cell "Dave at 4" is reached. On mouse-up, I replace the high-lighted cells with "<========>". I put "<==" in cell Dave at 1, "==>" in cell Dave at 4, and for all the cells inbetween, I put "===".

    That's it, it's that simple. Once they have finished, they print it off and they're done for that day.

    This is why my comments regarding the datagrid being developed with the assumption it's database related. This isn't. I guess what I need is more of a spreadsheet type control. The flexgrid was perfect for this. Implimenting the datagrid for this has been one drama after another. Your comments about "a bit of a learning curve" is a major understatement. This control is not intuitive at all. Anyway, enough moaning about that.

    Without doing any research on this right now, I see that I can add a "Microsoft Spreadsheet Control"...I am assuming that this is an Excel control, and if I use it there will be a requirement that the user has got MS Office installed on their PC, and probably has to be the same verison as mine...is this correct

    Dial, now that you understand exactly what I'm trying to achieve, do you think that the datagrid is what I should be using Is there any other standard control that I could use to acheive this

    I'm sure I am not the first person to come up against this "roadblock".

    Thanks again Dial, I look forward to your comments.

    MJ


  • Jose Rocco

    Sounds like a very dynamic solution is required. You can bind a DataTable to a DataGrid and you can create DataTables on the fly which isn't too hard. You will however need to create a DataTableStyle on the fly as well so you can have duplicate column headers. It can be done but like I said before there is a bit of learning curve involved. Also 30 columns sounds to me that FlexGrid or not, that may be a bit too much data to display comfortably as a row
  • victorlau

    The DataGrid is not a very intuative control to use but can be very flexible. It's just there is a bit of a learning curve involved.

    http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp

    Should answer most of your questions about the DataGrid

    To create column headers, widths etc you need to create a DataGridTableStyle. You can create a class for this or you can create a DataGridTableStyle by clicking the elipses on the DataGrid's TableStyles property in the Properties Window.

    Good luck :)


  • FlexGrid / Datagrid question