FabconIT
asked on
Finding the value of a cell or a column within a row in a datagrid
I have a program that is a datagrid combobox in VB.Net, I would like to find or put in a textbox each time I go down to the datagrid the value of a cell or column (let's say column 2), how do I do that ?
This is how my program was written. Â
Option Strict Off
Option Explicit On
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.OleDb
Imports System.Resources
Imports System.Runtime.InteropServ ices
Imports System.Data.SqlClient
Namespace DataGridTextBoxCombo
Â
  '/ <summary>
  '/ Summary description for Form1.
  '/ </summary>
  Public Class Form1
    Inherits System.Windows.Forms.Form
    Protected dsProducts As New DataSet
    Private dataGrid1 As System.Windows.Forms.DataG rid
    Private myDataSet As DataSet
    Private dataAdapter As OleDbDataAdapter
    Protected Const SQL_CONNECTION_STRING As String = _
    "Server=sql;" & _
    "DataBase=Management_Surve y;" & _
    "Integrated Security=SSPI"
    Protected Const MSDE_CONNECTION_STRING As String = _
      "Server=(sqltest)\NetSDK;" & _
      "DataBase=Management_Surve y;" & _
      "Integrated Security=SSPI"
    '/ <summary>
    '/ Required designer variable.
    '/ </summary>
    Protected Const PRODUCT_TABLE_NAME As String = "tblManager"
    Protected dvProducts As DataView
    Protected Const CAPTION_TITLE As String = "Bind Data to a ComboBox"
    Protected Const DEFAULT_SORT As String = "ManagerName ASC"
    ' Protected Const CAPTION_ICON_BUTTON As MsgBoxStyle = CType(MsgBoxStyle.Informat ion + MsgBoxStyle.OKOnly, MsgBoxStyle)
    Private components As System.ComponentModel.Cont ainer = Nothing
    Public Sub New()
      '
      ' Required for Windows Form Designer support
      '
      InitializeComponent()
     Â
      MakeDataSetAndBindGrid()
    End Sub 'New
    Private Sub MakeDataSetAndBindGrid()
      ' Set the connection and sql strings
      Dim connString As String = "Provider=sqloledb;Data Source = SQL; Initial Catalog = Management_Survey; Integrated Security = SSPI"
      Dim sqlString As String = "SELECT Description, ratingid FROM tblQuestion"
      dataAdapter = Nothing
      myDataSet = Nothing
      Try
        ' Connection object
        Dim connection As New OleDbConnection(connString )
        ' Create data adapter object
        dataAdapter = New OleDbDataAdapter(sqlString , connection)
       Â
        ' Create a dataset object and fill with data using data adapter's Fill method
        myDataSet = New DataSet
        dataAdapter.Fill(myDataSet , "tblQuestion")
        'now load the datatable for the bound combobox...
        'notice that the combobox & grid are NOT  bound to the same
        'table (if bound to the same table, you must have different binding contexts)
        sqlString = "SELECT ratingdesc, ratingid FROM tblRating order by ratingid"
        dataAdapter = New OleDbDataAdapter(sqlString , connection)
        dataAdapter.Fill(myDataSet , "tblrating")
        sqlString = "SELECT ManagerName, ManagerId FROM tblManager order by managerid"
        dataAdapter = New OleDbDataAdapter(sqlString , connection)
        dataAdapter.Fill(myDataSet , "tblManager")
        connection.Close()
      Catch ex As Exception
        MessageBox.Show(("Problem with access-  connection: " + connString + "      query: " + sqlString + ex.ToString()))
        Me.Close()
        Return
      End Try
      ' Create a table style that will hold the new column style
      ' that we set and also tie it to our customer's table from our DB
      Dim tableStyle As New DataGridTableStyle
      tableStyle.MappingName = "tblquestion"
      Dim dt As DataTable = myDataSet.Tables("tblquest ion")
      ' make the dataGrid use our new tablestyle and bind it to our table
      Dim i As Integer
      While i < dt.Columns.Count
        If i <> 1 Then
          Dim TextCol As New DataGridTextBoxColumn
          TextCol.MappingName = dt.Columns(i).ColumnName
          TextCol.HeaderText = dt.Columns(i).ColumnName
          TextCol.Width = 450
          tableStyle.GridColumnStyle s.Add(Text Col)
        Else
          Dim ComboTextCol As New DataGridComboBoxColumn
          ComboTextCol.MappingName = "ratingId" 'must be from the grid table...
          ComboTextCol.HeaderText = "Rating"
          ComboTextCol.Width = 120
          'DataView dv = new DataView(myDataSet.Tables[ "customerL ist"], "", "customerID", DataViewRowState.CurrentRo ws);
          ComboTextCol.ColumnComboBo x.DataSour ce = myDataSet.Tables("tblratin g").Defaul tView 'dv;
          ComboTextCol.ColumnComboBo x.DisplayM ember = "ratingdesc"
          ComboTextCol.ColumnComboBo x.ValueMem ber = "ratingID"
          tableStyle.PreferredRowHei ght = ComboTextCol.ColumnComboBo x.Height + 2
          tableStyle.GridColumnStyle s.Add(Comb oTextCol)
        End If
        i = i + 1
      End While
      dataGrid1.TableStyles.Clea r()
      dataGrid1.TableStyles.Add( tableStyle )
      dataGrid1.DataSource = dt
      'make it no append
      myDataSet.Tables("tblquest ion").Defa ultView.Al lowDelete = False
      myDataSet.Tables("tblquest ion").Defa ultView.Al lowNew = False
      myDataSet.Tables("tblquest ion").Defa ultView.Al lowEdit = False
    End Sub 'MakeDataSetAndBindGrid
   Â
    '/ <summary>
    '/ Clean up any resources being used.
    '/ </summary>
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
        If Not (components Is Nothing) Then
          components.Dispose()
        End If
      End If
      MyBase.Dispose(disposing)
    End Sub 'Dispose
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents cboRightCombo As System.Windows.Forms.Combo Box
    Friend WithEvents Button1 As System.Windows.Forms.Butto n
    Friend WithEvents TextBox1 As System.Windows.Forms.TextB ox
    Friend WithEvents Button2 As System.Windows.Forms.Butto n
    Private Sub InitializeComponent()
      Dim resources As System.Resources.ResourceM anager = New System.Resources.ResourceM anager(Get Type(Form1 ))
      Me.dataGrid1 = New System.Windows.Forms.DataG rid
      Me.Label1 = New System.Windows.Forms.Label
      Me.cboRightCombo = New System.Windows.Forms.Combo Box
      Me.Button1 = New System.Windows.Forms.Butto n
      Me.TextBox1 = New System.Windows.Forms.TextB ox
      Me.Button2 = New System.Windows.Forms.Butto n
      CType(Me.dataGrid1, System.ComponentModel.ISup portInitia lize).Begi nInit()
      Me.SuspendLayout()
      '
      'dataGrid1
      '
      Me.dataGrid1.AlternatingBa ckColor = System.Drawing.Color.Gains boro
      Me.dataGrid1.Anchor = CType((((System.Windows.Fo rms.Anchor Styles.Top Or System.Windows.Forms.Ancho rStyles.Bo ttom) _
            Or System.Windows.Forms.Ancho rStyles.Le ft) _
            Or System.Windows.Forms.Ancho rStyles.Ri ght), System.Windows.Forms.Ancho rStyles)
      Me.dataGrid1.BackColor = System.Drawing.Color.Silve r
      Me.dataGrid1.BackgroundCol or = System.Drawing.Color.Laven der
      Me.dataGrid1.BorderStyle = System.Windows.Forms.Borde rStyle.Fix edSingle
      Me.dataGrid1.CaptionBackCo lor = System.Drawing.Color.DarkS lateBlue
      Me.dataGrid1.CaptionFont = New System.Drawing.Font("Tahom a", 8.0!)
      Me.dataGrid1.CaptionForeCo lor = System.Drawing.Color.White
      Me.dataGrid1.CaptionText = "Rate your Manager/Supervisor"
      Me.dataGrid1.DataMember = ""
      Me.dataGrid1.FlatMode = True
      Me.dataGrid1.ForeColor = System.Drawing.Color.Black
      Me.dataGrid1.GridLineColor = System.Drawing.Color.White
      Me.dataGrid1.HeaderBackCol or = System.Drawing.Color.DarkG ray
      Me.dataGrid1.HeaderForeCol or = System.Drawing.Color.Black
      Me.dataGrid1.LinkColor = System.Drawing.Color.DarkS lateBlue
      Me.dataGrid1.Location = New System.Drawing.Point(16, 40)
      Me.dataGrid1.Name = "dataGrid1"
      Me.dataGrid1.ParentRowsBac kColor = System.Drawing.Color.Black
      Me.dataGrid1.ParentRowsFor eColor = System.Drawing.Color.White
      Me.dataGrid1.SelectionBack Color = System.Drawing.Color.DarkS lateBlue
      Me.dataGrid1.SelectionFore Color = System.Drawing.Color.White
      Me.dataGrid1.Size = New System.Drawing.Size(688, 536)
      Me.dataGrid1.TabIndex = 0
      '
      'Label1
      '
      Me.Label1.Location = New System.Drawing.Point(176, 88)
      Me.Label1.Name = "Label1"
      Me.Label1.Size = New System.Drawing.Size(112, 16)
      Me.Label1.TabIndex = 1
      '
      'cboRightCombo
      '
      Me.cboRightCombo.Font = New System.Drawing.Font("Micro soft Sans Serif", 9.75!, System.Drawing.FontStyle.R egular, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
      Me.cboRightCombo.Location = New System.Drawing.Point(16, 8)
      Me.cboRightCombo.Name = "cboRightCombo"
      Me.cboRightCombo.Size = New System.Drawing.Size(222, 24)
      Me.cboRightCombo.TabIndex = 2
      '
      'Button1
      '
      Me.Button1.Location = New System.Drawing.Point(256, 8)
      Me.Button1.Name = "Button1"
      Me.Button1.Size = New System.Drawing.Size(120, 23)
      Me.Button1.TabIndex = 3
      Me.Button1.Text = "Load Manager's List"
      '
      'TextBox1
      '
      Me.TextBox1.Location = New System.Drawing.Point(456, 8)
      Me.TextBox1.Name = "TextBox1"
      Me.TextBox1.TabIndex = 4
      Me.TextBox1.Text = ""
      '
      'Button2
      '
      Me.Button2.Location = New System.Drawing.Point(592, 8)
      Me.Button2.Name = "Button2"
      Me.Button2.TabIndex = 5
      Me.Button2.Text = "Button2"
      '
      'Form1
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
      Me.ClientSize = New System.Drawing.Size(712, 597)
      Me.Controls.Add(Me.Button2 )
      Me.Controls.Add(Me.TextBox 1)
      Me.Controls.Add(Me.Button1 )
      Me.Controls.Add(Me.cboRigh tCombo)
      Me.Controls.Add(Me.dataGri d1)
      Me.Controls.Add(Me.Label1)
      Me.Icon = CType(resources.GetObject( "$this.Ico n"), System.Drawing.Icon)
      Me.Name = "Form1"
      Me.StartPosition = System.Windows.Forms.FormS tartPositi on.CenterS creen
      Me.Text = "Fabcon Management Survey"
      CType(Me.dataGrid1, System.ComponentModel.ISup portInitia lize).EndI nit()
      Me.ResumeLayout(False)
    End Sub 'InitializeComponent
    <STAThread()> _
     Public Shared Sub Main()
      Application.Run(New Form1)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      BindtoDataset()
    End Sub
    Private Sub BindToDataSet()
      Try
        LoadData()
        cboRightCombo.DataSource = dvProducts
        cboRightCombo.DisplayMembe r = "ManagerName"
        cboRightCombo.ValueMember = "ManagerID"
      Catch exp As Exception
        MessageBox.Show(exp.Messag e, Me.Text)
      End Try
    End Sub
    Private Sub LoadData()
      Dim strConnection As String = SQL_CONNECTION_STRING
      Dim IsConnecting As Boolean = True
      While IsConnecting
        Try
          Dim northwindConnection As New SqlConnection(strConnectio n)
          Dim ProductAdapter As New SqlDataAdapter( _
            "SELECT * " _
            & "FROM tblManager", _
            northwindConnection)
          ProductAdapter.Fill(dsProd ucts, PRODUCT_TABLE_NAME)
          'create the dataview; use a constructor to specify
          ' the sort, filter criteria for performance purposes
          dvProducts = New DataView(dsProducts.Tables ("tblManag er"), "", DEFAULT_SORT, DataViewRowState.OriginalR ows)
          ' Data has been retrieved successfully Â
          ' Signal to break out of the loop by setting isConnecting to false.
          IsConnecting = False
          'Handle the situation where a connection attempt has failed
        Catch exc As Exception
          If strConnection = SQL_CONNECTION_STRING Then
            ' Couldn't connect to SQL Server.  Now try MSDE.
            strConnection = MSDE_CONNECTION_STRING
          Else
            ' Unable to connect to SQL Server or MSDE
          End If
        End Try
      End While
    End Sub
  Â
  End Class 'Form1
End Namespace 'DataGridTextBoxCombo
This is how my program was written. Â
Option Strict Off
Option Explicit On
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.OleDb
Imports System.Resources
Imports System.Runtime.InteropServ
Imports System.Data.SqlClient
Namespace DataGridTextBoxCombo
Â
  '/ <summary>
  '/ Summary description for Form1.
  '/ </summary>
  Public Class Form1
    Inherits System.Windows.Forms.Form
    Protected dsProducts As New DataSet
    Private dataGrid1 As System.Windows.Forms.DataG
    Private myDataSet As DataSet
    Private dataAdapter As OleDbDataAdapter
    Protected Const SQL_CONNECTION_STRING As String = _
    "Server=sql;" & _
    "DataBase=Management_Surve
    "Integrated Security=SSPI"
    Protected Const MSDE_CONNECTION_STRING As String = _
      "Server=(sqltest)\NetSDK;"
      "DataBase=Management_Surve
      "Integrated Security=SSPI"
    '/ <summary>
    '/ Required designer variable.
    '/ </summary>
    Protected Const PRODUCT_TABLE_NAME As String = "tblManager"
    Protected dvProducts As DataView
    Protected Const CAPTION_TITLE As String = "Bind Data to a ComboBox"
    Protected Const DEFAULT_SORT As String = "ManagerName ASC"
    ' Protected Const CAPTION_ICON_BUTTON As MsgBoxStyle = CType(MsgBoxStyle.Informat
    Private components As System.ComponentModel.Cont
    Public Sub New()
      '
      ' Required for Windows Form Designer support
      '
      InitializeComponent()
     Â
      MakeDataSetAndBindGrid()
    End Sub 'New
    Private Sub MakeDataSetAndBindGrid()
      ' Set the connection and sql strings
      Dim connString As String = "Provider=sqloledb;Data Source = SQL; Initial Catalog = Management_Survey; Integrated Security = SSPI"
      Dim sqlString As String = "SELECT Description, ratingid FROM tblQuestion"
      dataAdapter = Nothing
      myDataSet = Nothing
      Try
        ' Connection object
        Dim connection As New OleDbConnection(connString
        ' Create data adapter object
        dataAdapter = New OleDbDataAdapter(sqlString
       Â
        ' Create a dataset object and fill with data using data adapter's Fill method
        myDataSet = New DataSet
        dataAdapter.Fill(myDataSet
        'now load the datatable for the bound combobox...
        'notice that the combobox & grid are NOT  bound to the same
        'table (if bound to the same table, you must have different binding contexts)
        sqlString = "SELECT ratingdesc, ratingid FROM tblRating order by ratingid"
        dataAdapter = New OleDbDataAdapter(sqlString
        dataAdapter.Fill(myDataSet
        sqlString = "SELECT ManagerName, ManagerId FROM tblManager order by managerid"
        dataAdapter = New OleDbDataAdapter(sqlString
        dataAdapter.Fill(myDataSet
        connection.Close()
      Catch ex As Exception
        MessageBox.Show(("Problem with access-  connection: " + connString + "      query: " + sqlString + ex.ToString()))
        Me.Close()
        Return
      End Try
      ' Create a table style that will hold the new column style
      ' that we set and also tie it to our customer's table from our DB
      Dim tableStyle As New DataGridTableStyle
      tableStyle.MappingName = "tblquestion"
      Dim dt As DataTable = myDataSet.Tables("tblquest
      ' make the dataGrid use our new tablestyle and bind it to our table
      Dim i As Integer
      While i < dt.Columns.Count
        If i <> 1 Then
          Dim TextCol As New DataGridTextBoxColumn
          TextCol.MappingName = dt.Columns(i).ColumnName
          TextCol.HeaderText = dt.Columns(i).ColumnName
          TextCol.Width = 450
          tableStyle.GridColumnStyle
        Else
          Dim ComboTextCol As New DataGridComboBoxColumn
          ComboTextCol.MappingName = "ratingId" 'must be from the grid table...
          ComboTextCol.HeaderText = "Rating"
          ComboTextCol.Width = 120
          'DataView dv = new DataView(myDataSet.Tables[
          ComboTextCol.ColumnComboBo
          ComboTextCol.ColumnComboBo
          ComboTextCol.ColumnComboBo
          tableStyle.PreferredRowHei
          tableStyle.GridColumnStyle
        End If
        i = i + 1
      End While
      dataGrid1.TableStyles.Clea
      dataGrid1.TableStyles.Add(
      dataGrid1.DataSource = dt
      'make it no append
      myDataSet.Tables("tblquest
      myDataSet.Tables("tblquest
      myDataSet.Tables("tblquest
    End Sub 'MakeDataSetAndBindGrid
   Â
    '/ <summary>
    '/ Clean up any resources being used.
    '/ </summary>
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
        If Not (components Is Nothing) Then
          components.Dispose()
        End If
      End If
      MyBase.Dispose(disposing)
    End Sub 'Dispose
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents cboRightCombo As System.Windows.Forms.Combo
    Friend WithEvents Button1 As System.Windows.Forms.Butto
    Friend WithEvents TextBox1 As System.Windows.Forms.TextB
    Friend WithEvents Button2 As System.Windows.Forms.Butto
    Private Sub InitializeComponent()
      Dim resources As System.Resources.ResourceM
      Me.dataGrid1 = New System.Windows.Forms.DataG
      Me.Label1 = New System.Windows.Forms.Label
      Me.cboRightCombo = New System.Windows.Forms.Combo
      Me.Button1 = New System.Windows.Forms.Butto
      Me.TextBox1 = New System.Windows.Forms.TextB
      Me.Button2 = New System.Windows.Forms.Butto
      CType(Me.dataGrid1, System.ComponentModel.ISup
      Me.SuspendLayout()
      '
      'dataGrid1
      '
      Me.dataGrid1.AlternatingBa
      Me.dataGrid1.Anchor = CType((((System.Windows.Fo
            Or System.Windows.Forms.Ancho
            Or System.Windows.Forms.Ancho
      Me.dataGrid1.BackColor = System.Drawing.Color.Silve
      Me.dataGrid1.BackgroundCol
      Me.dataGrid1.BorderStyle = System.Windows.Forms.Borde
      Me.dataGrid1.CaptionBackCo
      Me.dataGrid1.CaptionFont = New System.Drawing.Font("Tahom
      Me.dataGrid1.CaptionForeCo
      Me.dataGrid1.CaptionText = "Rate your Manager/Supervisor"
      Me.dataGrid1.DataMember = ""
      Me.dataGrid1.FlatMode = True
      Me.dataGrid1.ForeColor = System.Drawing.Color.Black
      Me.dataGrid1.GridLineColor
      Me.dataGrid1.HeaderBackCol
      Me.dataGrid1.HeaderForeCol
      Me.dataGrid1.LinkColor = System.Drawing.Color.DarkS
      Me.dataGrid1.Location = New System.Drawing.Point(16, 40)
      Me.dataGrid1.Name = "dataGrid1"
      Me.dataGrid1.ParentRowsBac
      Me.dataGrid1.ParentRowsFor
      Me.dataGrid1.SelectionBack
      Me.dataGrid1.SelectionFore
      Me.dataGrid1.Size = New System.Drawing.Size(688, 536)
      Me.dataGrid1.TabIndex = 0
      '
      'Label1
      '
      Me.Label1.Location = New System.Drawing.Point(176, 88)
      Me.Label1.Name = "Label1"
      Me.Label1.Size = New System.Drawing.Size(112, 16)
      Me.Label1.TabIndex = 1
      '
      'cboRightCombo
      '
      Me.cboRightCombo.Font = New System.Drawing.Font("Micro
      Me.cboRightCombo.Location = New System.Drawing.Point(16, 8)
      Me.cboRightCombo.Name = "cboRightCombo"
      Me.cboRightCombo.Size = New System.Drawing.Size(222, 24)
      Me.cboRightCombo.TabIndex = 2
      '
      'Button1
      '
      Me.Button1.Location = New System.Drawing.Point(256, 8)
      Me.Button1.Name = "Button1"
      Me.Button1.Size = New System.Drawing.Size(120, 23)
      Me.Button1.TabIndex = 3
      Me.Button1.Text = "Load Manager's List"
      '
      'TextBox1
      '
      Me.TextBox1.Location = New System.Drawing.Point(456, 8)
      Me.TextBox1.Name = "TextBox1"
      Me.TextBox1.TabIndex = 4
      Me.TextBox1.Text = ""
      '
      'Button2
      '
      Me.Button2.Location = New System.Drawing.Point(592, 8)
      Me.Button2.Name = "Button2"
      Me.Button2.TabIndex = 5
      Me.Button2.Text = "Button2"
      '
      'Form1
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
      Me.ClientSize = New System.Drawing.Size(712, 597)
      Me.Controls.Add(Me.Button2
      Me.Controls.Add(Me.TextBox
      Me.Controls.Add(Me.Button1
      Me.Controls.Add(Me.cboRigh
      Me.Controls.Add(Me.dataGri
      Me.Controls.Add(Me.Label1)
      Me.Icon = CType(resources.GetObject(
      Me.Name = "Form1"
      Me.StartPosition = System.Windows.Forms.FormS
      Me.Text = "Fabcon Management Survey"
      CType(Me.dataGrid1, System.ComponentModel.ISup
      Me.ResumeLayout(False)
    End Sub 'InitializeComponent
    <STAThread()> _
     Public Shared Sub Main()
      Application.Run(New Form1)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      BindtoDataset()
    End Sub
    Private Sub BindToDataSet()
      Try
        LoadData()
        cboRightCombo.DataSource = dvProducts
        cboRightCombo.DisplayMembe
        cboRightCombo.ValueMember = "ManagerID"
      Catch exp As Exception
        MessageBox.Show(exp.Messag
      End Try
    End Sub
    Private Sub LoadData()
      Dim strConnection As String = SQL_CONNECTION_STRING
      Dim IsConnecting As Boolean = True
      While IsConnecting
        Try
          Dim northwindConnection As New SqlConnection(strConnectio
          Dim ProductAdapter As New SqlDataAdapter( _
            "SELECT * " _
            & "FROM tblManager", _
            northwindConnection)
          ProductAdapter.Fill(dsProd
          'create the dataview; use a constructor to specify
          ' the sort, filter criteria for performance purposes
          dvProducts = New DataView(dsProducts.Tables
          ' Data has been retrieved successfully Â
          ' Signal to break out of the loop by setting isConnecting to false.
          IsConnecting = False
          'Handle the situation where a connection attempt has failed
        Catch exc As Exception
          If strConnection = SQL_CONNECTION_STRING Then
            ' Couldn't connect to SQL Server.  Now try MSDE.
            strConnection = MSDE_CONNECTION_STRING
          Else
            ' Unable to connect to SQL Server or MSDE
          End If
        End Try
      End While
    End Sub
  Â
  End Class 'Form1
End Namespace 'DataGridTextBoxCombo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What do you want to do locate the cell where user wants to enter values???
If yes then use .CurrentCell
If you mean to say that you would like to show a textbox in the current cell so that user can edit, I think the DataGrid does it automatically for you..