MinimalTech
MinimalTech

Reputation: 891

How to add (or create) a String Collection Editor control in my Windows Form in C#?

I develop a Windows Forms application with C#. Inside the application I have a Form and, inside this form, I want to create something like a table / list-of-strings, to be able to give user the functionality to enter or delete it's strings.

The functionality I want to achieve is like the String Collection Editor you can find in a the ComboBox control, when you go in Properties -> Items -> [(Collection) ...]:

enter image description here

Does this control already exists in the Toolbox of Visual Studio? I cannot find something similar.

If not, how can I create it?

(Also, as an extension of the functionality of it, I want furthermore to add a "delete" button in each string entry, to be able the user to delete entries of the table. How can I also achieve this as a next step?)

I am using Visual Studio Enterprise 2017 - v15.9.14 and my application targets the .Net Framework 4.7.2.

Upvotes: 1

Views: 2531

Answers (1)

大陸北方網友
大陸北方網友

Reputation: 3767

A simple and straightforward way is to create a DataGridView without row&column header and border to hold the string.

DataGridViewTextBoxColumn tc = new DataGridViewTextBoxColumn();
tc.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns.Add(tc);

// Hide row&column header
dataGridView1.ColumnHeadersVisible = false;
dataGridView1.RowHeadersVisible = false;
// Hide border
dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

The test result,

enter image description here

Upvotes: 1

Related Questions