Click here to Skip to main content
15,910,877 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: .NET DLL in a VB6.0 Application Pin
coolestCoder11-Dec-07 0:15
coolestCoder11-Dec-07 0:15 
GeneralRe: .NET DLL in a VB6.0 Application [modified] Pin
andyORS11-Dec-07 0:48
andyORS11-Dec-07 0:48 
GeneralRe: .NET DLL in a VB6.0 Application Pin
coolestCoder11-Dec-07 3:09
coolestCoder11-Dec-07 3:09 
GeneralRe: .NET DLL in a VB6.0 Application Pin
Dave Kreskowiak11-Dec-07 4:13
mveDave Kreskowiak11-Dec-07 4:13 
GeneralFinding monthend date Pin
Mark0610-Dec-07 23:45
Mark0610-Dec-07 23:45 
GeneralRe: Finding monthend date Pin
Christian Graus10-Dec-07 23:54
protectorChristian Graus10-Dec-07 23:54 
Questiontry to using datagridview without dataset Pin
eyes200710-Dec-07 23:42
eyes200710-Dec-07 23:42 
GeneralRe: try to using datagridview without dataset Pin
John_Adams11-Dec-07 2:07
John_Adams11-Dec-07 2:07 
Hi,

The following code demonstrates one of the ways to fill up DataGridView without using DataSet.

BEGIN CODE

Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form

Private buttonPanel As New Panel
Private WithEvents songsDataGridView As New DataGridView
Private WithEvents addNewRowButton As New Button
Private WithEvents deleteRowButton As New Button

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

SetupLayout()
SetupDataGridView()
PopulateDataGridView()

End Sub

Private Sub songsDataGridView_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _
Handles songsDataGridView.CellFormatting

If Me.songsDataGridView.Columns(e.ColumnIndex).Name = _
"Release Date" Then

If e IsNot Nothing Then
If e.Value IsNot Nothing Then
Try
e.Value = DateTime.Parse(e.Value.ToString()) _
.ToLongDateString()
e.FormattingApplied = True
Catch ex As FormatException
Console.WriteLine("{0} is not a valid date.", e.Value.ToString())
End Try
End If
End If

End If

End Sub

Private Sub addNewRowButton_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles addNewRowButton.Click

Me.songsDataGridView.Rows.Add()

End Sub

Private Sub deleteRowButton_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles deleteRowButton.Click

If Me.songsDataGridView.SelectedRows.Count > 0 AndAlso _
Not Me.songsDataGridView.SelectedRows(0).Index = _
Me.songsDataGridView.Rows.Count - 1 Then

Me.songsDataGridView.Rows.RemoveAt( _
Me.songsDataGridView.SelectedRows(0).Index)

End If

End Sub

Private Sub SetupLayout()

Me.Size = New Size(600, 500)

With addNewRowButton
.Text = "Add Row"
.Location = New Point(10, 10)
End With

With deleteRowButton
.Text = "Delete Row"
.Location = New Point(100, 10)
End With

With buttonPanel
.Controls.Add(addNewRowButton)
.Controls.Add(deleteRowButton)
.Height = 50
.Dock = DockStyle.Bottom
End With

Me.Controls.Add(Me.buttonPanel)

End Sub

Private Sub SetupDataGridView()

Me.Controls.Add(songsDataGridView)

songsDataGridView.ColumnCount = 5
With songsDataGridView.ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(songsDataGridView.Font, FontStyle.Bold)
End With

With songsDataGridView
.Name = "songsDataGridView"
.Location = New Point(8, 8)
.Size = New Size(500, 250)
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = False

.Columns(0).Name = "Release Date"
.Columns(1).Name = "Track"
.Columns(2).Name = "Title"
.Columns(3).Name = "Artist"
.Columns(4).Name = "Album"
.Columns(4).DefaultCellStyle.Font = _
New Font(Me.songsDataGridView.DefaultCellStyle.Font, FontStyle.Italic)

.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.Dock = DockStyle.Fill
End With

End Sub

Private Sub PopulateDataGridView()

Dim row0 As String() = {"11/22/1968", "29", "Revolution 9", _
"Beatles", "The Beatles [White Album]"}
Dim row1 As String() = {"1960", "6", "Fools Rush In", _
"Frank Sinatra", "Nice 'N' Easy"}
Dim row2 As String() = {"11/11/1971", "1", "One of These Days", _
"Pink Floyd", "Meddle"}
Dim row3 As String() = {"1988", "7", "Where Is My Mind?", _
"Pixies", "Surfer Rosa"}
Dim row4 As String() = {"5/1981", "9", "Can't Find My Mind", _
"Cramps", "Psychedelic Jungle"}
Dim row5 As String() = {"6/10/2003", "13", _
"Scatterbrain. (As Dead As Leaves.)", _
"Radiohead", "Hail to the Thief"}
Dim row6 As String() = {"6/30/1992", "3", "Dress", "P J Harvey", "Dry"}

With Me.songsDataGridView.Rows
.Add(row0)
.Add(row1)
.Add(row2)
.Add(row3)
.Add(row4)
.Add(row5)
.Add(row6)
End With

With Me.songsDataGridView
.Columns(0).DisplayIndex = 3
.Columns(1).DisplayIndex = 4
.Columns(2).DisplayIndex = 0
.Columns(3).DisplayIndex = 1
.Columns(4).DisplayIndex = 2
End With

End Sub


<STAThreadAttribute()> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub

End Class

END CODE

Regards,
John Adams
ComponentOne LLC

GeneralRe: try to using datagridview without dataset Pin
Dave Kreskowiak11-Dec-07 3:07
mveDave Kreskowiak11-Dec-07 3:07 
Questionexporting data Pin
stavros10-Dec-07 23:13
stavros10-Dec-07 23:13 
GeneralRe: exporting data Pin
CKnig10-Dec-07 23:23
CKnig10-Dec-07 23:23 
GeneralRe: exporting data Pin
stavros13-Dec-07 7:02
stavros13-Dec-07 7:02 
GeneralRe: exporting data Pin
Christian Graus10-Dec-07 23:49
protectorChristian Graus10-Dec-07 23:49 
GeneralRe: exporting data Pin
stavros13-Dec-07 7:06
stavros13-Dec-07 7:06 
GeneralSystem.Transaction problem Pin
ayiteyashley10-Dec-07 22:39
ayiteyashley10-Dec-07 22:39 
Generalneed some help with my billing application Pin
jesseax10-Dec-07 20:55
jesseax10-Dec-07 20:55 
GeneralRe: need some help with my billing application Pin
Christian Graus10-Dec-07 21:33
protectorChristian Graus10-Dec-07 21:33 
GeneralRe: need some help with my billing application Pin
jesseax11-Dec-07 17:25
jesseax11-Dec-07 17:25 
Questionproblem with two dimensional array Pin
Meenge10-Dec-07 20:47
Meenge10-Dec-07 20:47 
GeneralRe: problem with two dimensional array Pin
Christian Graus10-Dec-07 21:05
protectorChristian Graus10-Dec-07 21:05 
GeneralRe: problem with two dimensional array Pin
CKnig10-Dec-07 23:25
CKnig10-Dec-07 23:25 
GeneralRe: problem with two dimensional array Pin
Meenge11-Dec-07 15:55
Meenge11-Dec-07 15:55 
Generali need some help with my billing appliation [modified] Pin
jesseax10-Dec-07 18:02
jesseax10-Dec-07 18:02 
GeneralRe: i need some help with my billing appliation Pin
Sathesh Sakthivel10-Dec-07 18:09
Sathesh Sakthivel10-Dec-07 18:09 
GeneralRe: i need some help with my billing appliation Pin
Christian Graus10-Dec-07 18:36
protectorChristian Graus10-Dec-07 18:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.