joeybagadonutz Posted November 28, 2003 Posted November 28, 2003 Hi, I have a datagrid on a page, and I would like to fire an event when someone clicks on either a row or a cell in the datagrid, to populate other textboxes on the page depending on what they select in the datagrid. Is there a way to do this? What is the syntax? thanks, -JBD Quote
Moderators Robby Posted November 28, 2003 Moderators Posted November 28, 2003 place this in the CurrentCellChanged event of the dg... dim myCellValue as string= CType(myDatagrid.Item(myDatagrid.CurrentRowIndex, 0), String) 0 is the column number Quote Visit...Bassic Software
joeybagadonutz Posted November 28, 2003 Author Posted November 28, 2003 so the currentcellchanged event will run just by clicking on a cell? Quote
Moderators Robby Posted November 28, 2003 Moderators Posted November 28, 2003 yup Quote Visit...Bassic Software
joeybagadonutz Posted November 28, 2003 Author Posted November 28, 2003 this works great thanks, but the only problem Im having now is that on the FIRST time I click in the cell, nothing happens but from then on when I click in the cell it does work, why is this not working on the first time? thanks. -JBD Quote
Moderators Robby Posted November 28, 2003 Moderators Posted November 28, 2003 You can use the Enter or Click event of the DG to check for the first time you click it. You will need to set a flag to determine this. Quote Visit...Bassic Software
joeybagadonutz Posted November 28, 2003 Author Posted November 28, 2003 Cool thanks very much. What exactly do you mean by "set a flag" though? Can you pleaase post an example? thanks. -JBD Quote
Moderators Robby Posted November 28, 2003 Moderators Posted November 28, 2003 Use a member boolean variable (form level) and and set it to true once the DG has been clicked for the first time. All this is because CurrentCellChanged and Click (or Enter) will all fire each time you click the grid, so you need to determine the very first time it's clicked. Quote Visit...Bassic Software
joeybagadonutz Posted November 28, 2003 Author Posted November 28, 2003 Okay, I'm a newbie but trying hard so please bear with me : ) so I set a variable at the top of the form, not in a sub right? (that makes it "form level") like this: Dim varFirstClick as boolean = false Then, when the datagrid is clicked, I run a sub for the click, and say if varFirstClick is false then Dim myCellValue As string= CType(myDatagrid.Item(myDatagrid.CurrentRowIndex, 0), String) varFirstClick = true end if Something like this? Am I missing anything? I really do appreciate your help, thanks much. -JBD Quote
Moderators Robby Posted November 28, 2003 Moderators Posted November 28, 2003 You got it exactly. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.