datagridview column names

B

Bill Cart

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?
 
P

Peter Duniho

[...]
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?

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
 
B

Bill Cart

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.



Peter Duniho said:
[...]
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?

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
 
P

Peter Duniho

[...]
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top