Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

DataGridView - strange

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ColoradoGeiger@gmail.com - 27 Mar 2008 22:31 GMT
I have a datagrid view that I have made in the designer.  When
compiled and data is loaded into it, it looks great.

I have this on page 1 of a tab control.  Pages 2 through N are created
on the fly in a loop, the code for that loop is below, as with the
datagrids on their pages.  The code below tries to copy all properties
from the grid that looks good (dgridMaster) to the one that I am
creating on the fly... but it doesn't work.  I am missing something?

-----------------------------------------------------------------------------
TabPage tab = new TabPage();
DataGridView dgv = new DataGridView();

dgv.DataSource = MyMagicDLL.GetTableData();
dgv.Name = dtCurrent.ToShortDateString();
dgv.Location = dgridMaster.Location;
dgv.Size = dgridMaster.Size;
dgv.SelectionMode = dgridMaster.SelectionMode;
dgv.ReadOnly = dgridMaster.ReadOnly;
dgv.DefaultCellStyle = dgridMaster.DefaultCellStyle;
dgv.AlternatingRowsDefaultCellStyle =
dgridMaster.AlternatingRowsDefaultCellStyle;
dgv.ColumnHeadersDefaultCellStyle =
dgridMaster.ColumnHeadersDefaultCellStyle;
dgv.RowHeadersDefaultCellStyle =
dgridMaster.RowHeadersDefaultCellStyle;
dgv.AutoSizeColumnsMode = dgridMaster.AutoSizeColumnsMode;
dgv.ScrollBars = dgridMaster.ScrollBars;

for (i = 0; i <= (dgv.Columns.Count - 1); i++)
{
   dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}

tab.Controls.Add(dgv);
tab.Name = tab.Text = "My table"
TabControl.TabPages.Add(tab);
-----------------------------------------------------------------------------

The differences i notice:
1. The grid created on the fly has sortable columns. And because of
this it takes up more space in the X axis since beside each Header
cell there is space to the right for the up or down arrow.

2. The size looks good until i maximize the window.  The original grid
adjust because it's anchor properties are set.  But I lose my scroll
bars on my new grid when I add the line

dgv.Anchor = dgridMaster.Anchor;

Any ideas?

Jason
Marc Gravell - 28 Mar 2008 06:31 GMT
When you run it in debug, do any columns exist at the point you
enumerate them? Only: you haven't added it to the parent form yet, so
there is no currency-manager, hence no metadata provider at this
point. I would expect to manipulate the columns only *after* it is on
a control. The simplest approach may be in the ColumnAdded event.

As for the others; check what other properties you have edited - the
ones in bold in the designer. See if you missed any... Dock for
example. This is one of those occasions when it would be tempting not
to use the IDE but to use the same block of code to gerenate all grids
(even the one on the first page) - at least they should look the
same ;-p

Marc
ColoradoGeiger@gmail.com - 28 Mar 2008 17:05 GMT
I had gone through my settings in the designer but I will double check
my work.  And I will look into the first idea too.  Thanks a bunch!

Jason

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.