make datagrid cell clickable (vb -2008) - access-2007

nokia123

Active member
Joined
May 1, 2011
Messages
29
Programming Experience
Beginner
how can i make a cell like if i select any cell , the new form should come up or anything which has been coded for that cell.
kindly also note that i have enabled sorting , so if i use rowindex and columnindex things may not work out properly as after sorting the cell index will be same (i think so) but the data feed in it will change accordingly.
i mean before sorting ,there is a "abc" feed in cell(0,0) but after sorting there may be "zbd" in the same cell. and if user select "zbd", he will get the same thing as coded for "abc"


i hope i made myself clear ,and hoping for any suggestion ,thank you ;)
 
Not very clear, no. Take a look at this:

Update Grid Row in Dialogue

If that doesn't answer your question, try again to provide a FULL and CLEAR explanation of what you have and what you want to do.
 
oki let me try to explain my problem again..
i have a database of 100 people. and first column in that database is "Name".
i want that if i click on any name ,the new from should come up or any message or anything based on the coding for that click should come up.
say ,these are few names out of that database
jhon
harry
micky
...
now if i click on jhon , a new form containing john detain should come up.

using rowindex and columnindex ,this can be done ,i think.
now suppose ,user sorted the database (as i have enabled sorting)
after sorting the name will display like this

harry
jhon
micky
here ,in the place of jhon , there is harry, if still the user click on harry, he will get whatever i have coded for that cell as only the data has been changed not the cell
indices.
 
buddy, after sorting the data is being changed though the cell index is same. you can try it yourself .

let suppose before sorting the first data is " abc " and the code for its is,
if e.rowindex = 0 and e.columnindex= 0 then
messagebox.show("hello abc ")
end if

// now suppose after sorting alphabetically,the data in first cell is "zyx" ,but here the rowindex and column index is
still same that is 0,0. even if i click on "zyx" ,i will get message as "hello abc " .
get my point?? if yes, suggest me how to overcome this



 
Buddy, I'm not stupid. I know that the rows change order when sorted. You also know that, so it would obviously be stupid for you to hard-code a specific row index when you know that the rows will change. It's quite simple; the user clicks on a cell, the grid raises an event, you handle that event and get the column and row indexes of the cell, you get the data from that cell. The sorting doesn't matter because you always know what cell was clicked, so you just get the data from that cell. It doesn't matter where that cell is in the grid.

Maybe if you told us what you're actually trying to achieve instead of vague examples with pointless messages. I've already shown you how to get the data from the row the user clicks. That's apparently not what you want yet you have made no effort to provide the full and clear explanation I requested. You've simply repeated yourself.
 
VB.NET:
   Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Dim ci As Integer = e.ColumnIndex
        Dim ri As Integer = e.RowIndex
'these are your coordinates
    End Sub

FYI usually not a good idea to start talking slick to the guy trying to help you out.
 
I m doing it the same way already but after sorting things getting me into trouble :( after storing indices in ci and ri what next?i mean how can i utilize it after sorting.. kindly note that i am a novice and my explanation about my problem may not look like up to the mark and that is why i use layman language while explaining my problem and people took it wrong way.
VB.NET:
   Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Dim ci As Integer = e.ColumnIndex
        Dim ri As Integer = e.RowIndex
'these are your coordinates
    End Sub

FYI usually not a good idea to start talking slick to the guy trying to help you out.
 
I am really very sorry ,i did not mean that .I can guess that you may not be stupid as your great number of posts say it all.
But with due respect,let me tell you that I am a novice in vb2008 and that is why i used a layman's logic while explaining my problem.but Apparently,I am not expert and can not talk in expert way. and yes about your query of full and clear explanation ,its just a database of 100 people with column name as " name,mobile number,address,pin code,character,behavior,blood group and all sort of these things ,nothing personal you see :) " If still something is wrong with my reply,kindly ,be cool, as i do not do it intentionally.
Lastly ,your saying about grid raises event and all that just went over my head , sorry. Would you like to explain it at my level of understanding ?
Buddy, I'm not stupid. I know that the rows change order when sorted. You also know that, so it would obviously be stupid for you to hard-code a specific row index when you know that the rows will change. It's quite simple; the user clicks on a cell, the grid raises an event, you handle that event and get the column and row indexes of the cell, you get the data from that cell. The sorting doesn't matter because you always know what cell was clicked, so you just get the data from that cell. It doesn't matter where that cell is in the grid.

Maybe if you told us what you're actually trying to achieve instead of vague examples with pointless messages. I've already shown you how to get the data from the row the user clicks. That's apparently not what you want yet you have made no effort to provide the full and clear explanation I requested. You've simply repeated yourself.
 
This will get you the cell whose content was clicked when the CellContentClick event is raised:
VB.NET:
Dim cellValue As Object = myDataGridView(e.ColumnIndex, e.RowIndex).Value
There are lots of other variations of event and cell position but it all comes down to the same thing: use the column and row index to get the desired cell and then get the value from that cell.
 
Back
Top