DataGridView - 删除底行 [英] DataGridView - Remove the bottom row
问题描述
我有一个DataGridView来自表格中几列的拉取数据,添加4列,2个用户输入和一个Shift,一个用于添加日期。
但我想要摆脱网格底部的底部*行。
如果我可以张贴一张图片,但它看起来像以下......
只需忽略-s,是的,它会在空白行上插入班次和日期。
| MACHINENUMBER | STYLEWIDTH |空间| SHIFT | PICKS | RUNTIME |日期|
1001 - - - - - - - - - - 1060GP0124 - - - 4 - - - 1 - - - 200 - - - 8 - - 02-01-2014
1002 - - - - - - - - - - 1065Gp0124 - - - 2 - - - 1 - - - 230 - - 7.5 - - 02-01-2014
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1 - - - - - - - - - - - - 02-01-2014
I have a DataGridView the a pull data from a few columns in a table, add 4 columns, 2 for User Entry and one Shift and one for date that are added.
But I want to get rid of the bottom * row at the bottom of the grid.
If I could post a picture i would, but it kind of looks like the following...
Just ignore the -'s, and yes it inserts the shift and date on the blank line.
| MACHINENUMBER | STYLEWIDTH | SPACES | SHIFT | PICKS | RUNTIME | DATE |
1001 - - - - - - - - - - 1060GP0124 - - - 4 - - - 1 - - - 200 - - - 8 - - 02-01-2014
1002 - - - - - - - - - - 1065Gp0124 - - - 2 - - - 1 - - - 230 - - 7.5 - - 02-01-2014
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1- - - - - - - - - - - - 02-01-2014
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim sql As String
Dim datepicked As Date
datepicked = DateTimePicker1.Text
'Checkbox Check Loop
If CheckBox1.CheckState = False And CheckBox2.CheckState = False And CheckBox3.CheckState = False Then
MessageBox.Show("Please select a Shift")
Exit Sub
End If
If CheckBox1.Checked = True And CheckBox2.Checked = True Then
MessageBox.Show("Please select a One Shift Only")
Exit Sub
End If
If CheckBox2.Checked = True And CheckBox3.Checked = True Then
MessageBox.Show("Please select a One Shift Only")
Exit Sub
End If
If CheckBox1.Checked = True And CheckBox3.Checked = True Then
MessageBox.Show("Please select a One Shift Only")
Exit Sub
End If
'Selection of Shift
If CheckBox1.Checked = True Then
sql = "SELECT MACHINENUMBER, STYLEWIDTH, SPACES FROM Loomset_GVL WHERE RunFlag1 = 1"
ElseIf CheckBox2.Checked = True Then
sql = "SELECT MACHINENUMBER, STYLEWIDTH, SPACES FROM Loomset WHERE RunFlag2 = 1"
ElseIf CheckBox3.Checked = True Then
sql = "SELECT MACHINENUMBER, STYLEWIDTH, SPACES FROM Loomset WHERE RunFlag3 = 1"
End If
'SQL Data connection
Dim sqlCon1 As New SqlConnection("Data Source=SERVER1\DEV01;database=Production;uid=sa;pwd=passwordhere")
Dim daSWC1 As New SqlDataAdapter(sql, sqlCon1)
Dim SQLcmdBuilder1 As New SqlCommandBuilder(daSWC1)
Dim ds1 As New DataSet
'Adds the columns Picks, Runtime and Date.
Dim AddCol1 As New DataGridViewTextBoxColumn
Dim AddCol2 As New DataGridViewTextBoxColumn
Dim AddCol3 As New DataGridViewTextBoxColumn
Dim AddCol4 As New DataGridViewTextBoxColumn
AddCol1.DataPropertyName = "Shift"
AddCol1.HeaderText = "Shift"
AddCol1.Name = "Shift"
AddCol2.DataPropertyName = "Picks"
AddCol2.HeaderText = "PICKS"
AddCol2.Name = "PICKS"
AddCol3.DataPropertyName = "RunTime"
AddCol3.HeaderText = "RunTime"
AddCol3.Name = "RunTime"
AddCol4.DataPropertyName = "Date"
AddCol4.HeaderText = "Date"
AddCol4.Name = "Date"
AddCol4.DefaultCellStyle.Format = "MM/dd/yyyy"
daSWC1.Fill(ds1, "MACHINENUMBER")
DataGridView1.DataSource = ds1.Tables(0)
DataGridView1.Columns.Add(AddCol1)
For Each dgvr As DataGridViewRow In DataGridView1.Rows
If CheckBox1.Checked Then
dgvr.Cells("Shift").Value = 1
ElseIf CheckBox2.Checked Then
dgvr.Cells("Shift").Value = 2
ElseIf CheckBox3.Checked Then
dgvr.Cells("Shift").Value = 3
End If
Next
DataGridView1.Columns.Add(AddCol2)
DataGridView1.Columns.Add(AddCol3)
DataGridView1.Columns.Add(AddCol4)
For Each dgvr As DataGridViewRow In DataGridView1.Rows
dgvr.Cells("Date").Value = datepicked
Next
End Sub
推荐答案
DataGridView1.AllowUserToAddRows = False
这篇关于DataGridView - 删除底行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!