Home > Net >  Winform, dataGridView bindings in a data source, including the Name attribute Name conflicts
Winform, dataGridView bindings in a data source, including the Name attribute Name conflicts

Time:09-22

A form, including the dataGridView only,
Design code
 
The namespace WindowsFormsApp1
{
Partial class Form1
{
///& lt; summary>
///the necessary design variables,
///& lt;/summary>
Private System.Com ponentModel. IContainer components=null;

///& lt; summary>
///clean up any resources being used,
///& lt;/summary>
///& lt; Param name="disposing & gt;" If should release the managed resource, is true; Otherwise it is false, & lt;/param>
Protected override void the Dispose (bool disposing)
{
If (disposing & amp; & (the components!=null))
{
Components. The Dispose ();
}
Base. The Dispose (disposing);
}

# region Windows forms designer generated code

///& lt; summary>
///designer support required methods - do not modify the
///use the code editor to modify the contents of this method,
///& lt;/summary>
Private void InitializeComponent ()
{
Enclosing dataGridView1=new System. Windows. Forms. The DataGridView ();
This. Id=new System. Windows. Forms. DataGridViewTextBoxColumn ();
This. Name=new System. Windows. Forms. DataGridViewTextBoxColumn ();
This. Price=new System. Windows. Forms. DataGridViewTextBoxColumn ();
((System.Com ponentModel. ISupportInitialize) (enclosing dataGridView1)). BeginInit ();
Enclosing SuspendLayout ();
//
//dataGridView1
//
This. DataGridView1. AllowUserToAddRows=false;
This. DataGridView1. AllowUserToDeleteRows=false;
This. DataGridView1. ColumnHeadersHeightSizeMode=System. Windows. Forms. DataGridViewColumnHeadersHeightSizeMode. AutoSize;
Enclosing dataGridView1. Columns. AddRange (new System. Windows. Forms. DataGridViewColumn [] {
This Id,
This. The Name,
This. Price});
This. DataGridView1. Location=new System. Drawing. The Point (74, 30);
This. DataGridView1. Name="dataGridView1";
This. DataGridView1. ReadOnly=true;
Enclosing dataGridView1. RowTemplate. Height=23;
This. DataGridView1. Size=new System. Drawing. The Size (522, 297);
Enclosing dataGridView1. TabIndex=0;
//
//Id
//
This. Id. The HeaderText="Id";
This. Id. Name="Id",
This. Id. ReadOnly=true;
//
//the Name
//
This. The Name. The HeaderText="Name";
This. The Name. Name="Name";
This. Name. ReadOnly=true;
//
//Price
//
This. Price. The HeaderText="Price";
This. Price. Name="Price";
This. Price. ReadOnly=true;
//
//Form1
//
Enclosing AutoScaleDimensions=new System. Drawing. SizeF (6 f, 12 f);
Enclosing AutoScaleMode=System. Windows. Forms. AutoScaleMode. The Font;
Enclosing ClientSize=new System. Drawing. The Size (800, 450);
This. Controls. The Add (enclosing dataGridView1);
This. Name="Form1";
This. The Text="Form1";
Enclosing the Load +=new System. EventHandler (enclosing the Form1_Load);
((System.Com ponentModel. ISupportInitialize) (enclosing dataGridView1)). The EndInit ();
Enclosing ResumeLayout (false);

}

# endregion

Private System. Windows, Forms DataGridView dataGridView1;
Private System. Windows. Forms. DataGridViewTextBoxColumn Id;
Private System. Windows. Forms. DataGridViewTextBoxColumn Name;
Private System. Windows. Forms. DataGridViewTextBoxColumn Price;
}
}



From here on out, only the code has a double meaning. Enclosing the Name
Logic code also come out good
 
using System;
using System.Collections.Generic;
Using System.Com ponentModel;
using System.Data;
Using System. Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Using System. Windows. Forms;

The namespace WindowsFormsApp1
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent();
}

Private void Form1_Load (object sender, EventArgs e)
{
Var bookList=new List ()
{
The new Book {Id=1, Name="Good Story", Price=335.2},
The new Book {Id=2, Name="Better Story", Price=335.2},
The new Book {Id=2, Name="Programer 's Story'", Price=335.2},
The new Book {Id=3, Name="Normal Story", Price=335.2},
The new Book {Id=4, Name="Good Story", Price=335.2}
};

DataGridView1. AutoGenerateColumns=false;
DataGridView1. The DataSource=bookList;
}
}
}


Compile error: CS0029 cannot converts type "string" implicit "System. Windows. Forms. DataGridViewTextBoxColumn WindowsFormsApp1" C: \ Users \ QLZCL \ source \ repos \ WindowsFormsApp1 \ WindowsFormsApp1 \ Form1 Designer. Activity of cs 78
This. Of the 78 line is the design document Name="Form1", because it has already been appointed a this. The Name is a list of attributes,

I want to ask, is this a bug, of course, can not use the name data source properties is ok, but the problem is very strange

CodePudding user response:

Tip is correct, change the idea to look at problems, encountered before, it is ok to remove,

CodePudding user response:

What's the strange, your name covers the definition of the original name, equivalent to two name
You define a variable type 2, how can not complain
  •  Tags:  
  • C#