Agregue botones a la vista de cuadrícula de datos en forma de Windows
Frecuentes
Visto 44,598 veces
1
I want to add two buttons onto datagridview. Now they are on the right side. But I want to locate them on the left.
The other thing is I want to add an update event for "Edit" button. Is it
private void Edit_Click(object sender, EventArgs e)
{
}
Código de formulario:
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'qDataSet.Metric' table.
// You can move, or remove it, as needed.
this.metricTableAdapter.Fill(this.qDataSet.Metric);
DataGridViewButtonColumn EditColumn = new DataGridViewButtonColumn();
EditColumn.Text = "Edit";
EditColumn.Name = "Edit";
EditColumn.DataPropertyName = "Edit";
dataGridView1.Columns.Add(EditColumn);
DataGridViewButtonColumn DelColumn = new DataGridViewButtonColumn();
DelColumn.Text = "Delete";
DelColumn.Name = "Delete";
DelColumn.DataPropertyName = "Delete";
dataGridView1.Columns.Add(DelColumn);
}
The image likes:
Gracias por su atención.
4 Respuestas
5
You seems to have design the datagridview from the designer.
You can use the wizard which allow to edit columns. There you'll add two columns (one for editing and the other for deleting). You can choose where you want to set those columns. The text of the button is defined using the property "Text", you can also set the property "UseColumnTextForButton".
You can manage easily in the CellContentClickEvent the column and row which is clicked and then do the job.
If you want to manage access right (like allowing someone to editing and someone else to not editing) you can play with show/hide of this column.
contestado el 03 de mayo de 12 a las 16:05
1
Vea DisplayIndex
The zero-based position of the column as it is displayed in the associated DataGridView, or -1 if the band is not contained within a control.
EditColumn.DisplayIndex = 0;
DelColumn.DisplayIndex = 1;
contestado el 03 de mayo de 12 a las 16:05
I guess that it is 0,1 rather than 1,2. Then how about event code? - user1108948
@Love - See aquí y aquí - SwDevMan81
0
You can't subscribe to the Edit button events directly.
So, the decision to subscribe to the CellClick
event and check which are pressed
And yes, for columns position set DisplayIndex
perfecta
contestado el 03 de mayo de 12 a las 16:05
0
DataGridViewButtonColumn ButtonColumn = new DataGridViewButtonColumn();
ButtonColumn.Name = "Print";
ButtonColumn.HeaderText = "Print";
ButtonColumn.FlatStyle = FlatStyle.Popup;
ButtonColumn.DefaultCellStyle.ForeColor = Color.White;
ButtonColumn.DefaultCellStyle.BackColor = Color.CadetBlue;
ButtonColumn.Text = "Print";
ButtonColumn.UseColumnTextForButtonValue = true;
int columnIndex = 12; /*your column index number*/
if (dtGridTicket.Columns["Print"] == null)
{
dtGridTicket.Columns.Insert(columnIndex, ButtonColumn);
}
If you load the page column index hide so you use
dtGridTicket.Columns.RemoveAt(12);
Respondido 07 Oct 20, 14:10
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# winforms data-binding dataset or haz tu propia pregunta.
I adde it. But the button doesn't show its text. What is the property? - user1108948
It's "Text" you can also use "UseColumnTextForButton". - ykatchou