Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a hyper link column in my datagrid view,can some one give me an idea how can i pop up the window when ever the hyper link column clicked and populate that particular value in the pop up window.

thanks in Advance
Posted
Comments
shan1395 10-Aug-11 22:23pm    
ErrGrid.CellClick += new DataGridViewCellEventHandler(ErrGrid_CellClick);

This event handler triggers any cell will click,how can i choose only it triggers when my hyperlink column cell clicked
shan1395 10-Aug-11 22:25pm    
void ErrGrid_CellClick(object sender, DataGridViewCellEventArgs e)
{
// Ignore clicks that are not on button cells.
if (e.RowIndex < 0 || e.ColumnIndex != ErrGrid.Columns["MessageId"].Index) return;


//// Retrieve the RowId
int RowId = (Int32)ErrGrid[0, e.RowIndex].Value;

Am getting an error "pecified cast is not valid".

Any help please

1 solution

Your best bet is when the cell is clicked, check the column in your code to respond only if the hyperlink was clicked.

Your error is in the cast ? Try using int.TryParse on Value.ToString, that will convert it if at all posslble. Also, try using your debugger to see what value you're getting and why it won't cast as it stands. A cast does not convert, it only casts.
 
Share this answer
 
Comments
shan1395 10-Aug-11 22:51pm    
thanks Christian Graus,

this line
if (e.RowIndex < 0 || e.ColumnIndex != ErrGrid.Columns["MessageId"].Index) return; will do the job if the hyperlink column clicked or not.

i will try to parse then.
i want to try one more thing here,how to popup the window when the hyperlink column clicked ?
shan1395 10-Aug-11 23:21pm    
Okie finally wrote the code

void ErrGrid_CellClick(object sender, DataGridViewCellEventArgs e)
{

// Ignore clicks that are not on button cells.
if (e.RowIndex < 0 || e.ColumnIndex != ErrGrid.Columns["MessageId"].Index) return;

//// Retrieve the Row Index
string RowId = ErrGrid[0, e.RowIndex].Value.ToString();
//// convert string to Interger
int RowIndex;
int.TryParse(RowId, out RowIndex);
//Retrive the Error Queue Message for that particular Row Index
string MesId = ErrGrid.Rows[RowIndex].Cells["Queue"].Value.ToString();
MessageBox.Show(MesId);

}

I need small help here,rather than using messagebox here is this anyway i can open new window (pop up) to display the message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900