problem with DataGridViewRow list

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I need to create some sort of wizard. In first step user would check item to buy, in second buyer (it would be application for seller) and in third step application would generate recipe. (im still on first step)

I have my datagrid with checkboxes. When i check checkbox that row is added to list, and when i remove checkbox that row is removed from list. What i want to do is pass that list to third step so i can use that info. Problem is when i sort that grid by clicking on header, it seems that all values in list get null value. Is there any way i can achieve what i want?

Thanks in forward

Heres my code:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Wizard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private string urlSlike;
private List<DataGridViewRow> list = new List<DataGridViewRow>();

private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the pi2013HajebdbDataSet.Tepih table. You can move, or remove it, as needed.
this.tepihTableAdapter.Fill(this.pi2013HajebdbDataSet.Tepih);

selectedRowIndex = 0;
DataGridViewRow selectedRow = dataGridView1.Rows[selectedRowIndex];
urlSlike = Convert.ToString(selectedRow.Cells[8].Value);

this.pictureBox1.Load(urlSlike);
}

private string sifraTepiha;
private int selectedRowIndex;

private void button2_Click(object sender, EventArgs e)
{
DataGridViewRow selectedRow = dataGridView1.Rows[selectedRowIndex];
urlSlike = Convert.ToString(selectedRow.Cells[8].Value);

this.pictureBox1.Load(urlSlike);
}

private void button1_Click(object sender, EventArgs e)
{
DataGridViewRow selectedRow = dataGridView1.Rows[selectedRowIndex];
urlSlike = Convert.ToString(selectedRow.Cells[9].Value);

this.pictureBox1.Load(urlSlike);
}

private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (!String.IsNullOrEmpty(sifraTepiha) && e.ListChangedType == ListChangedType.Reset)
{
int row = tepihBindingSource.Find("SifraTepiha", sifraTepiha);

dataGridView1.BeginInvoke((MethodInvoker)delegate()
{
dataGridView1.Rows[row].Selected = true;
dataGridView1.CurrentCell = dataGridView1[0, row];
});
}
}

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex == -1)
{
sifraTepiha = dataGridView1.SelectedRows[0].Cells["sifraTepihaDataGridViewTextBoxColumn"].Value.ToString();
}

else
{
selectedRowIndex = e.RowIndex;
DataGridViewRow selectedRow = dataGridView1.Rows[selectedRowIndex];
urlSlike = Convert.ToString(selectedRow.Cells[8].Value);

if ((Convert.ToString(selectedRow.Cells[8].Value) != this.pictureBox1.ImageLocation) && (Convert.ToString(selectedRow.Cells[9].Value) != this.pictureBox1.ImageLocation))
{
this.pictureBox1.Load(urlSlike);
}
}
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 7)
{
if (Convert.ToBoolean(dataGridView1.Rows[selectedRowIndex].Cells[chk.Name].Value) == false)
{
dataGridView1.Rows[selectedRowIndex].Cells[chk.Name].Value = true;

list.Add(dataGridView1.Rows[selectedRowIndex]);
}

else if (Convert.ToBoolean(dataGridView1.Rows[selectedRowIndex].Cells[chk.Name].Value) == true)
{
dataGridView1.Rows[selectedRowIndex].Cells[chk.Name].Value = false;

for (int i = list.Count - 1; i >= 0; i--)
{
if (list.Cells[sifraTepihaDataGridViewTextBoxColumn.Name].Value == dataGridView1.Rows[selectedRowIndex].Cells[sifraTepihaDataGridViewTextBoxColumn.Name].Value)
{
list.RemoveAt(i);
}
}
}
}
}
}
}

View the full article
 
Back
Top