datagrid event question

Posted on 2004-11-10
Last Modified: 2010-04-23
I'm trying to change the value of one column based on what the user typed in another column.
So if they enter in A in the first column, the second column shows "Apple".  
I can't seem to figure out what event I should be keying off of.

Thanks in advance.
Question by:DennisL
    LVL 19

    Expert Comment

    use the CurrentCellChanged event of the DataGrid
    Now here you can check whether in your particular column the user has typed A or B

    Now remember, in order to set the corresponding value of Apple and Boy in the other column you'll need to assign the value to the particular column of the particular row in the Underlying table.

    LVL 3

    Author Comment

    My issue with CurrentCellChanged is that it fires everytime when you navigate through different cells.  And you can't seem to find out what the last column or row that you were in.  This program will be querying a database to populate the second column, so I don't want to be refreshing every column/row everytime the user navigates through the cells.
    LVL 8

    Expert Comment

    hi try this

    in the currentcellchanged event and also rembember that rownumber begins with 0 and column numbers also begins with 0
    so row 1 is 0 and column 1 is also 0

    dim r as integer
    dim rowval as string
    r = DataGrid.CurrentCell.RowNumber
    rowval=datagrid.Item(r, 0) 'this gets the value in column 1
    if rowval="A" then
    datagrid.Item(r, 1)="Apple" ' this sets the value for column 2
    end if
    LVL 19

    Accepted Solution

    You'll need to check whether user has selected a new Row or if he has just changed cells within the same row

    For this keep a variable at Form Level wherin you'll have


    then in CellChanged event check if
    current DataGrid.CurrentCell.RowNumber is equal to the previous value or not


    Dim LastRow as Integer

    Then on CurrentCellChanged

    If Not LastRow=DataGrid.CurrentCell.RowNumber then
       LastRow=DataGrid.CurrentCell.RowNumber 'Store this value for next usage
       If DataGrid.CurrentCell.ColumnNumber=1 Then 'Your Column No. Here
             'Now Set the Value for the grid
       End If
    End If
    LVL 3

    Author Comment

    Not exactly what I was looking for, but it does work and gave me some ideas.

    I don't think I'll be using the datagrid for my next project.  haha.

    Thanks for the help and sorry for accepting so late.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now