<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Bart Mermuys,<br>
Thank you .<br>
This is working.<br>
<br>
<br>
private void Handle_CurrentCellChanged(object sender, System.EventArgs
e)<br>
{<br>
try <br>
{<br>
int newCurrentRow = dataGridParts.CurrentCell.RowNumber;<br>
int newCurrentCol =
dataGridParts.CurrentCell.ColumnNumber;<br>
int rowCount =
BindingContext[dataGridParts.DataSource,dataGridParts.DataMember].Count;<br>
object val =
(oldCurrentRow<rowCount)?dataGridParts[oldCurrentRow,
oldCurrentCol]:null;<br>
sqlConnection1.Close();<br>
if ( (val != null) && (val != DBNull.Value) <br>
&& (oldCurrentRow < rowCount) <br>
&& okToValidate <br>
&& !IsValidValue(oldCurrentRow,
oldCurrentCol, val.ToString())<br>
)<br>
{<br>
MessageBox.Show("Entry Error");<br>
okToValidate = false;<br>
dataGridParts.CurrentCell = new
DataGridCell(oldCurrentRow, oldCurrentCol);<br>
okToValidate = true;<br>
<br>
}<br>
else<br>
{<br>
oldCurrentRow = newCurrentRow;<br>
oldCurrentCol = newCurrentCol;<br>
}<br>
}<br>
<br>
<br>
catch (Exception ex)<br>
{<br>
MessageBox.Show(ex.ToString());<br>
<br>
}<br>
<br>
}<br>
<br>
<br>
<br>
[quoted text, click to view] Bart Mermuys wrote:
<blockquote cite="mid%23Kw8BnZ9FHA.808@TK2MSFTNGP09.phx.gbl" type="cite">
<pre wrap="">Hi,
[quoted text, click to view] "Stanislav Nedelchev" <a class="moz-txt-link-rfc2396E" href="mailto:stanislav.nedelchev@gmail.com"><stanislav.nedelchev@gmail.com></a> wrote in message
<a class="moz-txt-link-freetext" href="news:ulXBWsX9FHA.3908@TK2MSFTNGP10.phx.gbl">news:ulXBWsX9FHA.3908@TK2MSFTNGP10.phx.gbl</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Hi Bart
Thank you for your reply
I think the problem is when you click at end of the grid
new empty record is added and when you get back without making any
changes to new record datagrid is removing new record and then i get
this error
System.IndexOutOfRange.Exception: No value at index 3
</pre>
</blockquote>
<pre wrap=""><!---->
I don't know a way to detect the last row, but i do think it's possible to
protect yourself against accessing a row that has disappeared :
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
int newCurrentRow = dataGrid1.CurrentCell.RowNumber;
int newCurrentCol = dataGrid1.CurrentCell.ColumnNumber;
int rowCount =
BindingContext[dataGrid1.DataSource,dataGrid1.DataMember].Count;
object val = (oldCurrentRow<rowCount)?dataGrid1[oldCurrentRow,
oldCurrentCol]:null;
if ( (val != null) && (val != DBNull.Value) &&
(oldCurrentRow < rowCount) &&
okToValidate &&
!IsValidValue(oldCurrentRow, oldCurrentCol, val.ToString()))
{
MessageBox.Show("Entry Error");
okToValidate = false;
CheckAgain = false;
dataGrid1.CurrentCell = new DataGridCell(oldCurrentRow, oldCurrentCol);
okToValidate = true;
CheckAgain = true;
}
else
{
oldCurrentRow = newCurrentRow;
oldCurrentCol = newCurrentCol;
}
}//method
HTH,
Greetings
</pre>
<blockquote type="cite">
<pre wrap="">Best Regards
Stanislav.
[quoted text, click to view] Bart Mermuys wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,
[quoted text, click to view] "Stanislav Nedelchev" <a class="moz-txt-link-rfc2396E" href="mailto:stanislav.nedelchev@gmail.com"><stanislav.nedelchev@gmail.com></a> wrote in message
<a class="moz-txt-link-freetext" href="news:elT89SM9FHA.2040@TK2MSFTNGP14.phx.gbl">news:elT89SM9FHA.2040@TK2MSFTNGP14.phx.gbl</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Hi to all,
I have problem with detecting null values in datagrid cell
here is the example code i get i get runtime error when i'm trying to
convert datagrid cell to string if it have null value and i want to
make check if cell have null value i want to skip operation.
Here is the example code
</pre>
</blockquote>
<pre wrap="">Not sure if this will help but i rearranged your code a little, because
it
didn't seem to work correctly (though i did not get an Exception with
your
code), because the oldrow and oldcol weren't updated when the old cell
was
null and when validation failed they were updated when they shouldn't.
See
changes made: