A
A
AmoN2010-09-22 13:46:38
.NET
AmoN, 2010-09-22 13:46:38

DataGrid and parsing?

There is a code for parsing a link in the grid and deleting a row from the grid (I still can’t do it from the database). But, there is a problem, when I press parsing, a window pops up (which I made (Message) about the request to delete a row, and parsing does not occur. Tell me, how can I fix it?

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)<br/>
 {<br/>
 /*---Удаление строки---*/<br/>
<br/>
if (e.RowIndex != -1)<br/>
 {<br/>
 DialogResult result = MessageBox.Show(&quot;Вы УВЕРЕНЫ, что хотите удалить строку из таблицы?&quot;,<br/>
 &quot;Осторожно. Удаление строки из таблицы&quot;, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);<br/>
 switch (result)<br/>
 {<br/>
 case DialogResult.Yes:<br/>
 {<br/>
 SqlConnection connection = new SqlConnection(&quot;server=ROOT-ПК\\SQLEXPRESS; database=edik; uid=sa; pwd=123321&quot;);<br/>
 connection.Open();<br/>
 SqlCommand cmdDel = new SqlCommand(&quot;DELETE FROM edik_1 WHERE FeedID = @FeedID&quot;, connection);<br/>
 SqlParameter param = new SqlParameter();<br/>
 param.DbType = DbType.Int32;<br/>
 param.ParameterName = &quot;@FeedID&quot;;<br/>
 // MessageBox.Show(dataGridView1.CurrentRow.Cells[0].Value.ToString());<br/>
<br/>
//0 - это первая ячейка в текущей строке грида<br/>
<br/>
param.Value = dataGridView1.CurrentRow.Cells[0].Value;<br/>
 cmdDel.Parameters.Add(param);<br/>
 byte count = 0;<br/>
<br/>
try<br/>
 {<br/>
 count = (byte)cmdDel.ExecuteNonQuery();<br/>
 }<br/>
 catch (Exception ex)<br/>
 {<br/>
 MessageBox.Show(ex.ToString());<br/>
 }<br/>
 finally<br/>
 {<br/>
 if ((connection != null))<br/>
 {<br/>
 connection.Close();<br/>
 }<br/>
 }<br/>
<br/>
if (count &gt; 0)<br/>
 {<br/>
 dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);<br/>
 }<br/>
 <br/>
 if (e.ColumnIndex == 3) dataGridView1.Rows.RemoveAt(e.RowIndex);<br/>
 else if (e.ColumnIndex == 0)<br/>
 {<br/>
 /*---Парсинг---*/<br/>
 XmlTextReader reader = new XmlTextReader((sender as DataGridView)[e.ColumnIndex, e.RowIndex].Value.ToString());<br/>
 while (reader.Read())<br/>
 {<br/>
 switch (reader.Name)<br/>
 {<br/>
 case &quot;title&quot;:<br/>
 listBox1.Items.Add(reader.ReadString());<br/>
 break;<br/>
 case &quot;link&quot;:<br/>
 listBox1.Items.Add(reader.ReadString());<br/>
 break;<br/>
 case &quot;pubDate&quot;:<br/>
 listBox1.Items.Add(reader.ReadString());<br/>
 listBox1.Items.Add(&quot;\n&quot;);<br/>
 break;<br/>
 }<br/>
 } <br/>
 <br/>
 }<br/>
 break;<br/>
 }<br/>
<br/>
case DialogResult.No:<br/>
 {<br/>
 return;<br/>
 }<br/>
 }<br/>
 <br/>
 }<br/>
 }<br/>

It should be like this:
70d404101ff7.jpg
It used to work, before adding some features (which are also needed).
And now, like this:
3fad6ff55edd.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bounz, 2010-09-22
@Bounz

So you have the first if'om checking that the row index is not -1 and the question of deletion is immediately asked. You also need to wrap it with an if (e.ColumnIndex == 3) check, which goes further down the program.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question