[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Change value in datagridview cell

Posted on 2007-07-21
4
Medium Priority
?
588 Views
Last Modified: 2010-07-27
How can I go to a cell 7 and change its value in a datagridview1 where the value in cell 1 equals the value in datagridview2.

Datagridview1

Unit               Date              Available
110               4/4/07            No


Datagridview2

Unit              Name1                 Name2             Cleared
110              Smith                    Doe                 11:00

After I enter a time in the cleared cell of datagridview2 I want the No to change to Yes where Datagridview cell1 = datagridview cell1
0
Comment
Question by:wiswalld
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Priest04
ID: 19540252
If DataGridView1.Item(columnindex,rowindex).Value = DataGridView1.Item(columnindex,rowindex).Value then
    DataGridView1.Item(columnindex,rowindex).Value = "Yes"
End if

where columnindex/rowindex are the indeces of the cell column/row starting from 0. To get the current column/row index, use

DataGridView1.CurrentCell.Columnindex
DataGridView1.CurrentCell.Rowindex

YOu can use CellEndEdit event of DataGridView to do this comparation, which is fired right after the cell is finished editing.

Goran
0
 
LVL 13

Author Comment

by:wiswalld
ID: 19543882
If DataGridView1.Item(columnindex,rowindex).Value = DataGridView2.Item(columnindex,rowindex).Value then
    DataGridView1.Item(columnindex,rowindex).Value = "Yes"
End if

I don't know what the row or column index will be. Could be row 10 in datagridview2 and row 3 in datagridview1. I will need to search Datagridview1 column 0 and find the match to Datagridview2 column zero and then update column seven from Datagridview1 where they match.

Unit               Date              Available
100               4/4/07            Yes
110               4/4/07            No      < Row to match>


Datagridview2

Unit              Name1                 Name2             Cleared
110              Smith                    Doe                 11:00               <Row to match with using 110>

0
 
LVL 13

Author Comment

by:wiswalld
ID: 19544176
Something like this maybe:

If Me.Datagridview1("unit").Value = Me.datagridview2.CurrentRow.Cells(1).Value Then
            Datagridview1.CurrentRow.Cells(7).Value = "Yes"
        End If

Error here
Me.Datagridview1("unit").
0
 
LVL 18

Accepted Solution

by:
Priest04 earned 1000 total points
ID: 19544338
If datagridview is databound, then you can use Find method on its source, like a BindingSource.Find method. If it is not databound then you would need to manually loop and search for value, like

for i as integer = 0 to Me.datagridview1.rowcount -1
    if Me.datagridview1.rows(i).cells(0).value = Me.datagridview2.CurrentRow.Cells(1).Value Then
        Datagridview1.Rows(i).Cells(7).Value = "Yes"
        exit for
    End If
next i

Goran
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

834 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