doener

sup!

I have three problems. Answer to any or all of these problems is welcome.

I am using VC++ Visual Studio .NET Express edition. So i would appreciate if the answers are for this tool.

Prob1:

GridViewProgram->CurrentRow->Index  . This gives the index of the current selected row of the datagridview.What i want to do is i want to select a particular row in a datagridview when i know the index so that i can write something into this selected row. Please note that i know just the index of the row and i need to select this row in runtime.How do i do it

Prob2:

I am trying to figure out how i can allow a user to edit a row (which is by default read only)when he makes a mouse click on this particular row(cell). I did following, but it doesnt work.Please tell me the right way to do it.

 

private: System::Void GridViewProgram_CellContentClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {

GridViewProgram->CurrentCell->Selected = true;

GridViewProgram->BeginEdit(true);

}

Prob3:How can i check if a row has some data written init or not I want to do this coz some action ha to occur only if there is some data in the row...if this particular  row is empty, nothing should happen.

 

Thanks a lot!

Cheers!



Re: Visual C++ Express Edition Dtagridview problems!

JeroGrav

Prob1 : you just need to use the CurrentCell property again. as in

int TheRowIWant = 5;

dataGridView1.CurrentCell = dataGridView1.Rows[ TheRowIWant ].Cells[0];

Prob3: I think you will just have to iterate through all the cells in the row and check their values manually.






Re: Visual C++ Express Edition Dtagridview problems!

doener

Thanks for the answer for prob1.

I will try it out tomorrow.

For prob3 though, i dont have numbers in the datagridview cell...i have some text (strings) and some numbers in the cells.

I have to somehow check if there is some data in the cell...irrespective of datatyp!

Any suggestions

Cheers!





Re: Visual C++ Express Edition Dtagridview problems!

JeroGrav

I haven't checked, but my guess is that the DataGridViewCell.Value property will be null unless some thing is explicitly assigned into it.

So if you check the Value peoperty and it's null, then you can tell that it doesn't have anything in it - regardless of type.






Re: Visual C++ Express Edition Dtagridview problems!

doener

oh ok ! I will check it out tomorow and post my result here!

Cheers!





Re: Visual C++ Express Edition Dtagridview problems!

doener

Ok i have tested now!

if (GridViewProgram[index,2]->Value )

This works for me to check if there is some data in this particular cell or not!

So problem 3 is solved!

Cheers





Re: Visual C++ Express Edition Dtagridview problems!

doener

For problem 1:

GridViewProgram->CurrentCell = GridViewProgram->Rows[index]->Cells[0];

This works for me to set the row i want as active!

Thanks for your inputs!





Re: Visual C++ Express Edition Dtagridview problems!

JeroGrav

I was just looking through the MSDN doco and came across this property

DataGridViewCell.DefaultNewRowValue

I think it will be a better solution to your prob 3 than just checking for null.

Regards

Jero

Edit -

I mean doing

if(dataGridView1[1,1].Value == dataGridView1[1,1].DefaultNewRowValue)

{ ...

instead of

if(dataGridView1[1,1].Value == null)

{ ...