hello,
I get my values displayed in the datagrid on the click of search button.
In that datagrid there are several fields....among them one is the ID field....
When i click on the ID field that id should get displayed in the ID TEXT FIELD...
Well, below is the code for the same which i have wrote on the Cell click event
Help with Code Tags
(Toggle Plain Text)

Dim i = e.RowIndex
Dim j = e.ColumnIndex
txtefid.Text = dgfacenq.Item(i, j).Value

Dim i = e.RowIndex Dim j = e.ColumnIndex txtefid.Text = dgfacenq.Item(i, j).Value

HOWEVER THE PROBLEM IS that when i get more thatn 1 row displayed in the datagrid and if i click on any row except row 1 , the value of that ID is not displayed in the textfield !

Whats the prob?? any problem regarding increment ??

PLZ HELP ME OUT ITS VERY URGENT !!! PLZZZ WHT SHOULD ID DO TO OVERCUM THIS PROB ??

CYA
ROHAN

Recommended Answers

All 5 Replies

You only handle one value with what you have here. Think about it - how many i's can you have with what you have below? How many j's?

I understand you think since i,j would be different for each row,column that you have it covered but you only have one of each specified. In addition, you don't have anything like a foreach or any other statement that will iterate through more than the first one. How does the program know that you have more than one and to grab them as well?

Maybe you have more code that you didn't post?

Dim i = e.RowIndex
Dim j = e.ColumnIndex
txtefid.Text = dgfacenq.Item(i, j).Value

/// You did realize that this was the same thing repeated right after the first just in a different look right?

Dim i = e.RowIndex Dim j = e.ColumnIndex txtefid.Text = dgfacenq.Item(i, j).Value

In effect if you have this code this way in your program you've just done this

Dim i = e.RowIndex
        Dim j = e.ColumnIndex
        txtefid.Text = dgfacenq.Item(i, j).Value 
        
        Dim i = e.RowIndex
        Dim j = e.ColumnIndex
        txtefid.Text = dgfacenq.Item(i, j).Value

When i click on the ID field that id should get displayed in the ID TEXT FIELD...

do you mean display it on TextBox? if yes then use MouseUp event handler inorder to know when user select the cell, and then display the cell content in textbox

Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
        TextBox1.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, NumOfIDColumn)
End Sub

DataGrid1.CurrentCell.RowNumber will return current cell that user select
NumOfIDColumn refers to the ID column in your dataset if it's the first column then you will write

DataGrid1.Item(DataGrid1.CurrentCell.RowNumber,0)

Note that even when user clicked the Name column in first row , the program will still display the ID in textbox
see this link

I hope that will help you

thanks for your timely help!

cya
Rohan

do you mean display it on TextBox? if yes then use MouseUp event handler inorder to know when user select the cell, and then display the cell content in textbox

Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
        TextBox1.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, NumOfIDColumn)
End Sub

DataGrid1.CurrentCell.RowNumber will return current cell that user select
NumOfIDColumn refers to the ID column in your dataset if it's the first column then you will write

DataGrid1.Item(DataGrid1.CurrentCell.RowNumber,0)

Note that even when user clicked the Name column in first row , the program will still display the ID in textbox
see this link

I hope that will help you

HI...i am not getting the desired output! i mean i am getting only errors.
Firstly have written that code under the MouseUp event of my datagrid .Is it necessary to write only under MouseUp? Why not under Cell Click / CellContent Click?

when i take my mouse over my id which is the first row in the datagrid nothing appears in the text box.
Yeah before that when i write this code :

DataGrid1.Item(DataGrid1.CurrentCell.RowNumber,0)

with ofcourse modification accordingly i get error as to System.........cannot convert to String. So i add

DataGrid1.Item(DataGrid1.CurrentCell.RowNumber,0).ToString

Is it correct ??

If i click on the cell i get another bigggggggg error....

Plz help me out soon ! plzzzz awating your quick response..

C my prob is :
I search the name of the enq. . When the particular say xyz enq.is found it appears in the datagrid below along with its id and other details.
So now when i will click on the ID ( first Column,row in the datagrid) that same id should appear in the TEXTBOX.

Plzzzzzzzz help me out !

Is it necessary to write only under MouseUp? Why not under Cell Click / CellContent Click?

o, not necessary but I thought it will work
Because I remember that when I once used click event it was fired only when I click the header of datagrid not the cell content :S , you can try (or search on net) for what each event do

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.