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# / July 2007

Tip: Looking for answers? Try searching our database.

datagridview column names

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Cart - 25 Jul 2007 16:51 GMT
I have a datagridview that was created by dragging an SQL stored procedure
onto the form. The SQL query has fields for Monday, Tuesday, etc.

I am trying to set some of the values with the DefaultValuesNeeded event.
When I right click on the control and select Edit Columns I can see a column
that appears to be named Monday.

The code is:
private void spApplicantMealListDataGridView_DefaultValuesNeeded(object
sender, DataGridViewRowEventArgs e)
{
  e.Row.Cells[9].Value = ThisClientId;
  e.Row.Cells["Monday"].Value = 0;
}

When I run the program I get an error: {"Column named Monday cannot be
found.\r\nParameter name: columnName"}

I go into Edit columns and Click on Add new column and select Monday as a
DataBound column. I add the column and then I see two columns that appear to
be named Monday. I run the program and then it works and shows the correct
data in both of the columns!! I can delete the original column and it works
correctly from then on.

Why? What are the default names for the columns?
Peter Duniho - 25 Jul 2007 20:41 GMT
> [...]
> When I run the program I get an error: {"Column named Monday cannot be
[quoted text clipped - 10 lines]
>
> Why? What are the default names for the columns?

I don't know.  But do keep in mind that the column has a Name and a  
Title.  The Title is what the user sees, the Name is whatever is used  
internally to track the column.  I guess that somehow the SQL store  
procedure sets the column names based on its own ideas, maybe including  
the source database name or something like that.

You could probably reset the names yourself after running the query, by  
copying the Title property to the Name property, if that's what you want  
to do.

Pete
Bill Cart - 26 Jul 2007 13:46 GMT
It appears that when you drag and drop a stored procedure (and probally a
table) that it shows up in the designer with the field names from the query
but hidden in the "Wizard" code it uses names like
private System.Windows.Forms.DataGridViewTextBoxColumn
dataGridViewTextBoxColumn10;

So even though the Column Editor shows the name you would expect that is not
it's real name.

I would hope that in the next version they either start showing the "real
name" in the Column Editor or start giving the Columns the row names from
the query.

>> [...]
>> When I run the program I get an error: {"Column named Monday cannot be
[quoted text clipped - 22 lines]
>
> Pete
Peter Duniho - 26 Jul 2007 18:36 GMT
> [...]
> I would hope that in the next version they either start showing the "real
> name" in the Column Editor or start giving the Columns the row names from
> the query.

I don't think you're going to see either change happen.  The name  
generated is consistent with other usual Designer behavior: a new variable  
gets named according to its type (converted to "camel case" by lowering  
the first character) and a trailing integer reflecting the numeric  
instance in order of creation.

Likewise, for obvious reasons it is much more user-friendly for the column  
HeaderText property to be set to the actual name of the field from the  
database rather than the variable name.

Note that the Name property of the instance is not required to match the  
variable name.  It does by default, but you should be able to change it  
after the fact to match whatever you need it to be.  Such as being  
identical to the HeaderText property.  As I suggested.  Is there something  
about that suggestion that's not working for you?

Pete

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.