Click here to Skip to main content
15,916,600 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Programs For Mobiles - VB.Net 2008 Pin
Paramu197326-Jun-10 21:06
Paramu197326-Jun-10 21:06 
QuestionDataGrid Window Forms Pin
.NetDeveloper0925-Jun-10 8:34
.NetDeveloper0925-Jun-10 8:34 
AnswerRe: DataGrid Window Forms Pin
DaveAuld25-Jun-10 9:44
professionalDaveAuld25-Jun-10 9:44 
GeneralRe: DataGrid Window Forms [modified] Pin
.NetDeveloper0926-Jun-10 6:38
.NetDeveloper0926-Jun-10 6:38 
GeneralRe: DataGrid Window Forms Pin
DaveAuld26-Jun-10 7:02
professionalDaveAuld26-Jun-10 7:02 
GeneralRe: DataGrid Window Forms Pin
.NetDeveloper0926-Jun-10 7:16
.NetDeveloper0926-Jun-10 7:16 
GeneralRe: DataGrid Window Forms Pin
DaveAuld26-Jun-10 7:53
professionalDaveAuld26-Jun-10 7:53 
GeneralRe: DataGrid Window Forms [modified] Pin
DaveAuld26-Jun-10 8:24
professionalDaveAuld26-Jun-10 8:24 
The example code below will create an internal data object to bind some test data to a datagridview, and then allow the user to click a cell and transfer the cells value to a textbox.
The DataGridView is named DataGridView1 TheDGV and the textbox is named TextBox1

VB
Public Class Form1

    Private _ProductList As List(Of Product) = New List(Of Product)

    Private Class Products
        Private _ProductList As List(Of Product)

        Public Sub AddProduct(ByVal NewProduct As Product)
            _ProductList.Add(NewProduct)
        End Sub

    End Class

    Private Class Product
        Private _ProductID As String
        Private _Price As Double

        Public Sub New(ByVal ProductID As String, ByVal Price As Double)
            _ProductID = ProductID
            _Price = Price
        End Sub

        Public ReadOnly Property ProductID() As String
            Get
                Return _ProductID
            End Get
        End Property

        Public ReadOnly Property Price() As Double
            Get
                Return _Price
            End Get
        End Property

    End Class

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

        _ProductList.Add(New Product("Product1", 100))
        _ProductList.Add(New Product("Product2", 200))
        _ProductList.Add(New Product("Product3", 300))
        _ProductList.Add(New Product("Product4", 400))
        _ProductList.Add(New Product("Product5", 500))

        TheDGV.DataSource = _ProductList

    End Sub

    Private Sub TheDGV_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles TheDGV.CellClick
        'Use this if you just want to transfer the value when the cell is clicked
        TextBox1.Text = TheDGV.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
    End Sub

    Private Sub TheDGV_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles TheDGV.CellContentClick
        'Use this if you want it to transfer the value when the actual text within the cell is clicked
        TextBox1.Text = TheDGV.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()

    End Sub
End Class


[Edit: I had the wrong name of the DataGridView]
Dave

Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com


modified on Sunday, June 27, 2010 2:38 AM

GeneralRe: DataGrid Window Forms Pin
.NetDeveloper0926-Jun-10 13:12
.NetDeveloper0926-Jun-10 13:12 
Questionsearch items in Datagridview Pin
zafax_25-Jun-10 1:21
zafax_25-Jun-10 1:21 
AnswerRe: search items in Datagridview Pin
Scubapro25-Jun-10 2:05
Scubapro25-Jun-10 2:05 
GeneralRe: search items in Datagridview Pin
zafax_25-Jun-10 2:36
zafax_25-Jun-10 2:36 
GeneralRe: search items in Datagridview Pin
Scubapro25-Jun-10 3:03
Scubapro25-Jun-10 3:03 
GeneralRe: search items in Datagridview Pin
zafax_25-Jun-10 5:41
zafax_25-Jun-10 5:41 
GeneralRe: search items in Datagridview Pin
riced25-Jun-10 6:09
riced25-Jun-10 6:09 
GeneralRe: search items in Datagridview Pin
Eddy Vluggen25-Jun-10 6:41
professionalEddy Vluggen25-Jun-10 6:41 
GeneralRe: search items in Datagridview Pin
zafax_25-Jun-10 21:38
zafax_25-Jun-10 21:38 
GeneralRe: search items in Datagridview Pin
Eddy Vluggen26-Jun-10 1:11
professionalEddy Vluggen26-Jun-10 1:11 
GeneralRe: search items in Datagridview Pin
zafax_26-Jun-10 4:13
zafax_26-Jun-10 4:13 
GeneralRe: search items in Datagridview Pin
Eddy Vluggen26-Jun-10 5:02
professionalEddy Vluggen26-Jun-10 5:02 
GeneralRe: search items in Datagridview Pin
zafax_26-Jun-10 5:09
zafax_26-Jun-10 5:09 
GeneralRe: search items in Datagridview Pin
DaveAuld25-Jun-10 3:05
professionalDaveAuld25-Jun-10 3:05 
AnswerRe: search items in Datagridview Pin
Luc Pattyn25-Jun-10 2:06
sitebuilderLuc Pattyn25-Jun-10 2:06 
GeneralRe: search items in Datagridview Pin
zafax_25-Jun-10 2:39
zafax_25-Jun-10 2:39 
AnswerRe: search items in Datagridview Pin
riced25-Jun-10 2:12
riced25-Jun-10 2:12 

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.