How to find out if a row in a DataGridView has been changed

T

Tony Johansson

Hello!

I have a DataGridView with 5 columns and a save button that I use to save
the contens to a textFile.
Everything works fine I can enter value in the columns and then save to a
textfile by clicking on the Save button.
Below is the event handler for the save button

The dataGridView is called dgLager
_rowIndexHit is a genering List instance with ints where a store all row
index that I have clicked in.
In the text file a store the last productnumber that I have in the textfile.
I get that last productnumber used by calling
FileManager.UpdateProductNumber.
This ValidateMyRow method just check if every cell in a row has been given a
value
I have a class called Product which is used to hold products like book, DVD
and games and such things.
I save to the textfile by calling Save on the static class FileManager.

Now to my question I wonder what I can do to find out if a row in a
DataGridView has been changed.?
I want some suggestions what I can do.

I must say that I have more to do on this DataGridView functionality because
I haven't started
yet with the function to read textfile and fill the DataGridVies with the
text file contents.

private void BtnProductSave_Click(object sender, EventArgs e)
{
if (_rowIndexHit.Count > 0)
FileManager.UpdateProductNumber(_currentProductNumber.ToString());

foreach (int row in _rowIndexHit)
{
string myAddedRow = dgLager.Rows[row].AccessibilityObject.Value;

string[] myRow = myAddedRow.Split(new char[] { ';' });
if (!ValidateMyRow(myRow))
{
MessageBox.Show(this,"All values in a row must be entered",
"Validating Input",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

//enum columnType { Namn, Pris, Produktnummer, Antal, Typ };
Product myProduct = new Product(myRow[(int)columnType.Namn],
int.Parse(myRow[(int)columnType.Pris]),
int.Parse(myRow[(int)columnType.Produktnummer]),
int.Parse(myRow[(int)columnType.Antal]),
myRow[(int)columnType.Typ]);

FileManager.Save(myProduct);
}
_rowIndexHit.Clear();
}

//Tony
 
T

Tony Johansson

Hello!

No I must use a textFile as I mentioned..

//Tony

Cor Ligthert said:
Tony,

As you use a datatable as a datasource then it is easy to find in the
rowstate of a datarow

http://msdn.microsoft.com/en-us/library/system.data.datarowstate.aspx

Cor


Tony Johansson said:
Hello!

I have a DataGridView with 5 columns and a save button that I use to save
the contens to a textFile.
Everything works fine I can enter value in the columns and then save to a
textfile by clicking on the Save button.
Below is the event handler for the save button

The dataGridView is called dgLager
_rowIndexHit is a genering List instance with ints where a store all row
index that I have clicked in.
In the text file a store the last productnumber that I have in the
textfile.
I get that last productnumber used by calling
FileManager.UpdateProductNumber.
This ValidateMyRow method just check if every cell in a row has been
given a
value
I have a class called Product which is used to hold products like book,
DVD
and games and such things.
I save to the textfile by calling Save on the static class FileManager.

Now to my question I wonder what I can do to find out if a row in a
DataGridView has been changed.?
I want some suggestions what I can do.

I must say that I have more to do on this DataGridView functionality
because
I haven't started
yet with the function to read textfile and fill the DataGridVies with the
text file contents.

private void BtnProductSave_Click(object sender, EventArgs e)
{
if (_rowIndexHit.Count > 0)

FileManager.UpdateProductNumber(_currentProductNumber.ToString());

foreach (int row in _rowIndexHit)
{
string myAddedRow =
dgLager.Rows[row].AccessibilityObject.Value;

string[] myRow = myAddedRow.Split(new char[] { ';' });
if (!ValidateMyRow(myRow))
{
MessageBox.Show(this,"All values in a row must be entered",
"Validating Input",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

//enum columnType { Namn, Pris, Produktnummer, Antal, Typ };
Product myProduct = new Product(myRow[(int)columnType.Namn],

int.Parse(myRow[(int)columnType.Pris]),

int.Parse(myRow[(int)columnType.Produktnummer]),

int.Parse(myRow[(int)columnType.Antal]),

myRow[(int)columnType.Typ]);

FileManager.Save(myProduct);
}
_rowIndexHit.Clear();
}

//Tony
 
C

Cor Ligthert[MVP]

Tony Johansson said:
Hello!

No I must use a textFile as I mentioned..
Yes and, what has that to do with no DataTable.

A DataTable is just a simple class that fits easily to Data Controls.

It is simply to write as XML file, but with some more work as CSV or
whatever you want.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top