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 / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

datagridview - don't want any rows selected initially....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oli - 08 Feb 2007 16:16 GMT
hi all - try as I might I can't get my datagridview to *not* select
(and hence highlight) a row...

...any help appreciated,
cheers,
O.
ClayB - 08 Feb 2007 16:25 GMT
Code like this in Form.Load avoids a selected current cell for me.

               this.dataGridView1.CurrentCell = null;

===================
Clay Burch
Syncfusion, Inc.
Oli - 08 Feb 2007 18:18 GMT
hmm - doesn't work for me :(
ClayB - 09 Feb 2007 10:31 GMT
I think in order for the null CurrentCell to work, the grid cannot be
the active control on the form when the form first appears. If the
form with the grid has other controls on it, you could set the
taborder such that the grid has a higher tabindex property than one of
the other controls on the form. Or, you could explicilty set the
form's activecontrol to some other control on the form. If all I do is
drop a DataGridView and a button on a form, add a form.Load event with
the code below, then the form displays with no row marked in the grid.
If I comment out the CurrentCell = null line, then cell 0,0 is
selected when the form appears. How does your use case differ?

       private void Form1_Load(object sender, EventArgs e)
       {
           #region Get the DataSource
           DataTable dt = new DataTable("MyTable");
           int nCols = 4;
           int nRows = 20;
           Random r = new Random(123345345);
           for (int i = 0; i < nCols; i++)
               dt.Columns.Add(new DataColumn(string.Format("Col{0}",
i), typeof(int)));
           for (int i = 0; i < nRows; ++i)
           {
               DataRow dr = dt.NewRow();
               for (int j = 0; j < nCols; j++)
                   dr[j] = r.Next(10);
               dt.Rows.Add(dr);
           }
           #endregion

           grid.DataSource = dt; //grid is a DataGridView
           this.ActiveControl = this.button1;
           grid.CurrentCell = null;
       }
=================
Clay Burch
Syncfusion, Inc.

Rate this thread:







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.