Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Columns and Rows

Status
Not open for further replies.
Joined
Nov 19, 2003
Messages
117
Location
US
I'm developing an application with uses a datagrid, the first column of the datagrid is a dropdown to select an ItemNumber, But i only want to display one row i don't want a column with every item in its own row with a dropdown of all the items. I want to all so add a two colums that come up without any data in them a column amount packed and a column total packing time, but for some reason i'm unable to add them unless they have data.
Well here is my code i hope somebody has and idea or answer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

TDBDate.Value = Now

GetEmp()

MakeDataSet()
dgPacking.SetDataBinding(dsTrial, "Trial")
AddCustomDataTableStyle()

End Sub


Private Sub MakeDataSet()
conMain = New SqlConnection(ConnectionString)


Dim daTrial As New SqlDataAdapter
daTrial.SelectCommand = New SqlCommand

Dim CmdTrial As New SqlCommand
Dim dsTrial2 As New DataSet

Try

With daTrial.SelectCommand
.Connection = conMain
.CommandType = CommandType.StoredProcedure
.CommandText = "PKA_GetItems"

End With

Catch ex As SqlException
MessageBox.Show(ex.Message & " " & ex.Number)

End Try



daTrial.Fill(dsTrial, "Trial")
Dim dtTrial As DataTable

dtTrial = New DataTable("Items")

'Create Three Columns
Dim ColItemID As DataColumn
ColItemID = New DataColumn("ItemID")

Dim ColTimeEach As DataColumn
ColTimeEach = New DataColumn("TimeEach")

Dim ColQtyPacked As DataColumn
ColQtyPacked = New DataColumn("QtyPacked")
ColQtyPacked.DataType = GetType(Integer)


Dim ColTotalTime As DataColumn
ColTotalTime = New DataColumn("TotalTime")
ColTotalTime.DataType = GetType(Integer)

dtTrial.Columns.Add(ColItemID)
dtTrial.Columns.Add(ColTimeEach)
dtTrial.Columns.Add(ColQtyPacked)
dtTrial.Columns.Add(ColTotalTime)

'Add the tables to the DataSet
dsTrial2.Tables.Add(dtTrial)

'Populate the table
Dim dsRow As DataRow

For Each dsRow In dsTrial.Tables("Trial").Rows

Next


End Sub



Private Sub AddCustomDataTableStyle()
Dim dsRow As DataRow

Dim ts1 As DataGridTableStyle
ts1 = New DataGridTableStyle
ts1.MappingName = "Trial"

'Alternating Color
ts1.AlternatingBackColor = Color.FromArgb(CType(234, Byte), CType(234, Byte), CType(234, Byte))

'add Column Combo box
Dim combotextcol As DataGridComboBoxColumn
combotextcol = New DataGridComboBoxColumn
combotextcol.MappingName = "ItemID"
combotextcol.HeaderText = "Item ID"
combotextcol.Width = 75

ts1.GridColumnStyles.Add(combotextcol)
'Populate
For Each dsRow In dsTrial.Tables("Trial").Rows

combotextcol.ColumnComboBox.Items.Add(dsRow("ItemID"))
'combotextcol.ColumnComboBox.DataSource = dsTrial.Tables("Trial")
'combotextcol.ColumnComboBox.DisplayMember = "ItemID"

Next
combotextcol.ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList
dgPacking.TableStyles.Add(ts1)

' a) make the row height a little larger to handle minimum combo height
ts1.PreferredRowHeight = (combotextcol.ColumnComboBox.Height + 3)
'Adds Two columns with textbox style
Dim textcol As DataGridTextBoxColumn
textcol = New DataGridTextBoxColumn
textcol.MappingName = "ItemDesc"
textcol.HeaderText = "ItemDesc"
textcol.Width = 200
ts1.GridColumnStyles.Add(textcol)

textcol = New DataGridTextBoxColumn
textcol.MappingName = "PackingTime"
textcol.HeaderText = "Packing Time"
textcol.Width = 50
ts1.GridColumnStyles.Add(textcol)

'ts1.GridColumnStyles.Add(textcol)
textcol = New DataGridTextBoxColumn
textcol.MappingName = "QtyPacked"
textcol.HeaderText = "QtyPacked"
textcol.Width = 50
ts1.GridColumnStyles.Add(textcol)

'ts1.GridColumnStyles.Add(textcol)
textcol = New DataGridTextBoxColumn
textcol.MappingName = "TotalTime"
textcol.HeaderText = "TotalTime"
textcol.Width = 50
ts1.GridColumnStyles.Add(textcol)

End Sub

Private Sub dataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgEmployee.MouseUp

Dim pt = New Point(e.X, e.Y)

Dim hti As DataGrid.HitTestInfo = dgEmployee.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then

dgEmployee.CurrentCell = New DataGridCell(hti.Row, hti.Column)

dgEmployee.Select(hti.Row)

End If

End Sub
Private Sub txtWorkMinutes_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If TDBNWorkMin.Value > 59 Then
MessageBox.Show("You cannot work more the 60 minutes in One hour")
TDBNWorkMin.Focus()
TDBNWorkMin.Value = 0

End If
End Sub

Sincerely,
Fritts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top