[英]Adding to DataGridView by column or cell
Is it possible to add unbound data to a DataGridView by column/cell rather than by the whole row so that the next empty cell in a column is filled similar to this in excel是否可以按列/单元格而不是整行将未绑定的数据添加到 DataGridView,以便在 excel 中填充类似于此的列中的下一个空单元格
ActiveSheet.Range("A100").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
This is what I've been doing for each button click这就是我为每个按钮单击所做的事情
Private Sub Button1_Click(sender As Object, e As EventArgs)
Button1.Text = Label1.Text
Me.DataGridView1.Rows.Add(Button1.Text, "", "")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs)
Button2.Text = Label2.Text
Me.DataGridView1.Rows.Add("", Button2.Text, "")
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs)
Button3.Text = Label3.Text
Me.DataGridView1.Rows.Add("", "", Button3.Text)
End Sub
and then deleting the blank cells in excel然后删除 excel 中的空白单元格
At the moment it results in three rows rather than one row Adding a new row each time one of the buttons is pressed目前它导致三行而不是一行每次按下一个按钮时添加一个新行
Edit:编辑:
What I was hoping for was to have a number of buttons associated with each column (Button 1 & 4 with column 1, 2 with 2 etc).我希望的是有一些与每列相关联的按钮(按钮 1 和 4 与列 1、2 与 2 等)。
If the user pressed button 1 2 times and button 4 3 times it would fill column 1 5 times.如果用户按下按钮 1 2 次和按钮 4 3 次,它将填充列 1 5 次。 Then when button 2 was pressed it would fill column 2 but start in row 1 rather than a new 6th row same for button 3.
然后,当按下按钮 2 时,它将填充第 2 列,但从第 1 行开始,而不是与按钮 3 相同的新的第 6 行。
So in the end it would be a row where all 3 columns are filled in the row rather than just one column with two blanks.因此,最后将是一行,其中所有 3 列都填充在该行中,而不是只有一列有两个空白。
I did have it as labels that were added when a submit button was pressed but that meant that the buttons still had to be pressed in a sequence that filled column 1, 2 & 3 before they were submitted我确实将它作为在按下提交按钮时添加的标签,但这意味着在提交按钮之前仍必须按填充列 1、2 和 3 的顺序按下按钮
Any help or pointers greatly appreciated非常感谢任何帮助或指示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.