open a new window in a datagrid's selected row

rajibsaha

New member
Joined
May 3, 2005
Messages
4
Programming Experience
Beginner
hello,

I am using vb.net. can anybody tell me how to fire the click event in a datagrid row. actually i want to open a new window in a datagrid row.when i am clicking a new row of a particular column i need to catch the click event of that row, Can anybody help me.

Thanks in advance....
 

alaric

Well-known member
Joined
Oct 12, 2005
Messages
53
Programming Experience
Beginner
hi,

maybe a bit late. I've been struggling the same. Found the solution on the forum;

1st make you DS public shared. like;
VB.NET:
[COLOR=#0000ff]Public [/COLOR][SIZE=2][COLOR=#0000ff]Shared[/COLOR][/SIZE][SIZE=2] ds_ab [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] dataset[/SIZE]
then on datagrid doubleclick event;
VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] DataGrid1_DoubleClick([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Datagrid1.DoubleClick
[/SIZE][SIZE=2][COLOR=#008000]'read 1st column of the datagrid
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strstudentId [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Datagrid1.Item([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Datagrid1.CurrentRowIndex, 0)
[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] frmAdresbook_ed [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] frmAdresbook_ed
[/SIZE][SIZE=2][COLOR=#008000]'Set the values in the dialogue TextBoxes from the selected row in the Datagrid.
[/COLOR][/SIZE][SIZE=2]frmAdresbook_ed.txtstudentId.Text = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Datagrid1.Item([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Datagrid1.CurrentRowIndex, 0).ToString()
frmAdresbook_ed.txtfirstnaam.Text = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Datagrid1.Item([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Datagrid1.CurrentRowIndex, 1).ToString()
frmAdresbook_ed.txtlastnaam.Text = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Datagrid1.Item([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Datagrid1.CurrentRowIndex, 2).ToString()
[/SIZE]
etcetc.
[SIZE=2][COLOR=#008000]'Display the new form.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] frmAdresbook_ed.ShowDialog() <> DialogResult.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff]end sub
[/COLOR][/SIZE]
hope this helps.
 
Top Bottom