DataGridViewComboBoxColumn.DropDownWidth Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit la largeur des listes des zones de liste déroulante.
public:
property int DropDownWidth { int get(); void set(int value); };
public int DropDownWidth { get; set; }
member this.DropDownWidth : int with get, set
Public Property DropDownWidth As Integer
Valeur de propriété
Largeur de la liste déroulante en pixels. La valeur par défaut est 1.
Exceptions
La propriété CellTemplate possède la valeur null
.
Exemples
L’exemple de code suivant montre comment utiliser un DataGridViewComboBoxColumn pour faciliter l’entrée de données dans la TitleOfCourtesy
colonne. Cet exemple fait partie d’un exemple plus large disponible dans la rubrique vue d’ensemble de la DataGridViewComboBoxColumn classe.
private:
DataGridViewComboBoxColumn^ CreateComboBoxColumn()
{
DataGridViewComboBoxColumn^ column =
gcnew DataGridViewComboBoxColumn();
{
column->DataPropertyName = ColumnName::TitleOfCourtesy.ToString();
column->HeaderText = ColumnName::TitleOfCourtesy.ToString();
column->DropDownWidth = 160;
column->Width = 90;
column->MaxDropDownItems = 3;
column->FlatStyle = FlatStyle::Flat;
}
return column;
}
private:
void SetAlternateChoicesUsingDataSource(DataGridViewComboBoxColumn^ comboboxColumn)
{
{
comboboxColumn->DataSource = RetrieveAlternativeTitles();
comboboxColumn->ValueMember = ColumnName::TitleOfCourtesy.ToString();
comboboxColumn->DisplayMember = comboboxColumn->ValueMember;
}
}
private:
DataTable^ RetrieveAlternativeTitles()
{
return Populate("SELECT distinct TitleOfCourtesy FROM Employees");
}
String^ connectionString;
private:
DataTable^ Populate(String^ sqlCommand)
{
SqlConnection^ northwindConnection = gcnew SqlConnection(connectionString);
northwindConnection->Open();
SqlCommand^ command = gcnew SqlCommand(sqlCommand, northwindConnection);
SqlDataAdapter^ adapter = gcnew SqlDataAdapter();
adapter->SelectCommand = command;
DataTable^ table = gcnew DataTable();
adapter->Fill(table);
return table;
}
// Using an enum provides some abstraction between column index
// and column name along with compile time checking, and gives
// a handy place to store the column names.
enum class ColumnName
{
EmployeeID,
LastName,
FirstName,
Title,
TitleOfCourtesy,
BirthDate,
HireDate,
Address,
City,
Region,
PostalCode,
Country,
HomePhone,
Extension,
Photo,
Notes,
ReportsTo,
PhotoPath,
OutOfOffice
};
private DataGridViewComboBoxColumn CreateComboBoxColumn()
{
DataGridViewComboBoxColumn column =
new DataGridViewComboBoxColumn();
{
column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
column.DropDownWidth = 160;
column.Width = 90;
column.MaxDropDownItems = 3;
column.FlatStyle = FlatStyle.Flat;
}
return column;
}
private void SetAlternateChoicesUsingDataSource(DataGridViewComboBoxColumn comboboxColumn)
{
{
comboboxColumn.DataSource = RetrieveAlternativeTitles();
comboboxColumn.ValueMember = ColumnName.TitleOfCourtesy.ToString();
comboboxColumn.DisplayMember = comboboxColumn.ValueMember;
}
}
private DataTable RetrieveAlternativeTitles()
{
return Populate("SELECT distinct TitleOfCourtesy FROM Employees");
}
string connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
private DataTable Populate(string sqlCommand)
{
SqlConnection northwindConnection = new SqlConnection(connectionString);
northwindConnection.Open();
SqlCommand command = new SqlCommand(sqlCommand, northwindConnection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table);
return table;
}
// Using an enum provides some abstraction between column index
// and column name along with compile time checking, and gives
// a handy place to store the column names.
enum ColumnName
{
EmployeeId,
LastName,
FirstName,
Title,
TitleOfCourtesy,
BirthDate,
HireDate,
Address,
City,
Region,
PostalCode,
Country,
HomePhone,
Extension,
Photo,
Notes,
ReportsTo,
PhotoPath,
OutOfOffice
};
Private Function CreateComboBoxColumn() _
As DataGridViewComboBoxColumn
Dim column As New DataGridViewComboBoxColumn()
With column
.DataPropertyName = ColumnName.TitleOfCourtesy.ToString()
.HeaderText = ColumnName.TitleOfCourtesy.ToString()
.DropDownWidth = 160
.Width = 90
.MaxDropDownItems = 3
.FlatStyle = FlatStyle.Flat
End With
Return column
End Function
Private Sub SetAlternateChoicesUsingDataSource( _
ByVal comboboxColumn As DataGridViewComboBoxColumn)
With comboboxColumn
.DataSource = RetrieveAlternativeTitles()
.ValueMember = ColumnName.TitleOfCourtesy.ToString()
.DisplayMember = .ValueMember
End With
End Sub
Private Function RetrieveAlternativeTitles() As DataTable
Return Populate( _
"SELECT distinct TitleOfCourtesy FROM Employees")
End Function
Private connectionString As String = _
"Integrated Security=SSPI;Persist Security Info=False;" _
& "Initial Catalog=Northwind;Data Source=localhost"
Private Function Populate(ByVal sqlCommand As String) As DataTable
Dim northwindConnection As New SqlConnection(connectionString)
northwindConnection.Open()
Dim command As New SqlCommand(sqlCommand, _
northwindConnection)
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = command
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
adapter.Fill(table)
Return table
End Function
' Using an enum provides some abstraction between column index
' and column name along with compile time checking, and gives
' a handy place to store the column names.
Enum ColumnName
EmployeeId
LastName
FirstName
Title
TitleOfCourtesy
BirthDate
HireDate
Address
City
Region
PostalCode
Country
HomePhone
Extension
Photo
Notes
ReportsTo
PhotoPath
OutOfOffice
End Enum
Remarques
Cette propriété correspond à la DataGridViewComboBoxCell.DropDownWidth propriété du CellTemplate membre.
L’obtention ou la définition de cette propriété obtient ou définit la DropDownWidth propriété de l’objet retourné par la CellTemplate propriété. La définition de cette propriété définit également la DropDownWidth propriété de chaque cellule de la colonne. Pour remplacer la valeur spécifiée pour les cellules individuelles, définissez les valeurs des cellules après avoir défini la valeur de colonne.