Results 1 to 7 of 7

Thread: Datagrid Cell Coordinate

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Datagrid Cell Coordinate

    How can I find the X and Y position of a datagrid cell? I can provide the row and cell number if needed.

    Thanks heaps

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Datagrid Cell Coordinate

    Is it really a DataGrid, or is it actually a DataGridView? If it's a DataGrid, is it really a WinForms DataGrid, or is it aactually an ASP.NET or WPF DataGrid?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Datagrid Cell Coordinate

    SDorry DataGridView

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Datagrid Cell Coordinate

    Have you read the documentation for the DataGridView class? You should, because the answer to your question is in there. You should always read the relevant documentation first.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Datagrid Cell Coordinate

    I have, can you point it out for me. it's not the grid i'm after but selected cells.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Datagrid Cell Coordinate

    I have this but how can I loop through all cells not just 'selected' cells

    vb Code:
    1. Dim cell As DataGridViewCell
    2.             For Each cell In DataGridView1.SelectedCells
    3.  
    4.                 If cell.Value.ToString = String.Empty Then
    5.                     MessageBox.Show("Empty")
    6.                     'Dim newTXT As New TextBox
    7.                     'newTXT.Text = "DD"
    8.                 End If
    9.  
    10.                 Dim r As Rectangle = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCellAddress.X, DataGridView1.CurrentCellAddress.Y, False)
    11.                 MessageBox.Show(r.X & " - " & r.Y)
    12.  
    13.             Next

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Datagrid Cell Coordinate

    You would use two nested loops. You could either use For Each loops, looping through the Rows of the grid and then the Cells of the row, or you could use For loops using the RowCount and ColumnCount and indexing the grid itself by column index and row index.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width