Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving DataGridView

I open two files into 2 seperate DGVs.. Once opened and the button "Format" is clicked, it matches all of the lines in the two seperate DGVs and copies it into a new DGV.

The first DGV looks like this (column labels):

Name    P/N    X    Y    Rotation    PkgStyle

and the second DGV looks like this:

PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time

The two files will match the PkgStyle and concat the rest of the lines together to get the third DGV that looks like this:

Name    P/N    X    Y    Rotation    PkgStyle    PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time

Now, as you may expect there could be possible lines that do not match properly and will not combine the two sets of lines from the two files. If this is the case it will only input the information from the first file and not the second.

So some sample data might look like this:

Name    P/N    X    Y    Rotation    PkgStyle    PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time
J11     1234   12  7     180         9876         9876    THETHING   1        1           1        UNI      12MM     1MS
R90     2222   19  9     0           1255         1255    ITEM       2        1           1        UNI2     5MM      1MS
J18     9845   11  4     270         456
C127    1111   05  1     270         5555         5555    ITEM2      3        1           1        UNI      8MM      0.1MS

SO

The third row (not including the titles of the columns) has blank cells in it. When the user changes the cell data in those blank spots, I would like to add it to a text document that already contains similar data. So, if the user added 456 someITEM 4 1 1 UNI2 9MM 10MS to the DataGridView lines that were blank, I want to add that to the end of the a file that already contains data. I want to only add the line if all of the column cells are filled in for each row. The output can just be space delimited.

Can anyone help me with this?

like image 389
theNoobGuy Avatar asked Sep 01 '11 17:09

theNoobGuy


People also ask

What is the difference between DataGrid and DataGridView?

The DataGrid control is limited to displaying data from an external data source. The DataGridView control, however, can display unbound data stored in the control, data from a bound data source, or bound and unbound data together.

What is difference between GridView and DataGridView?

The DataGrid and the GridView controls have different event models. The DataGrid control raises single events for operations, while the GridView control is capable of both pre-operation and post-operation events. The GridView control supports the Sorting event that occurs when a field is sorted.

What is DataGridView virtual mode?

Virtual mode is designed for use with very large stores of data. When the VirtualMode property is true , you create a DataGridView with a set number of rows and columns and then handle the CellValueNeeded event to populate the cells.


1 Answers

You can use this link to check selected cell is null/empty or not with some modification: C# DataRow Empty-check

I suppose 3 datagrid: dg1, dg2, dg3 accordingly. Columns of dg3 compose of columns of dg1 and dg2.

public static string GetNewData(DataRow row)
{
  string res = string.Empty;
  if (row == null) throw new ArgumentNullException("row");

  foreach (DataColumn column in dg2.Columns)
    if (row.IsNull(column.ColumnName) || string.IsNullOrEmpty(row[column.ColumnName].ToString()))
      return string.Empty;
    else
      res += row[column.ColumnName] + " ";

  return res.Trim();
}

Hope this help.

like image 114
Thinhbk Avatar answered Oct 18 '22 11:10

Thinhbk