Hi,
I'm making an application that uses DataGridView. While designing the layout I placed a DataGridView and named it dgrComponents.
Everything was fine, until I wanted to add a table programmically and also use it like this:
Code Snippet
if
(dgrComponents.SelectedRows.Count > 0)
{
DataGridViewRow dr = dgrComponents.SelectedRows[0];
String filename = dr.Cells["colPath"].Value.ToString();
if (filename.Length > 0)
{
returnValue =
new MyComponent(filename);
}
}
As you see it above, that's how I see it as well. It complains it cannot find dgrComponents.
Looking into the form.designer.cs I found this:
Code Snippet
///
<summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.
DataGridView dgrComponents;
dgrComponents =
new System.Windows.Forms.DataGridView();
((System.ComponentModel.
ISupportInitialize)(dgrComponents)).BeginInit();
...
All seems well until you discover that dgrComponents is declared as a local variable to the InitializeComponent function. Which means I can't access it from my code. All other components are declared as private outside of the function.
If I move it and declare it as private, just like all the other components, it all works well......until I add/moveany component and it will remove my changes and move the dgrComponents into the function and make it local again. Which breaks my code so I have to go into the form.designer.cs and move it again.
This is extremely annoying. Anybody seen this before? Any fix?
/Xtremer