3 Attachment(s)
How to combine 2 data grid view to one data grid view and insert it to new table
Hi All,
I want to improve my program (MONITORING OUTPUT SYSTEM) and create report for it.
Here it looks like:
datagridview on the left is from datasource it auto count the OUTPUT, then datagridview on the right is manual data means no datasource and users must keyin the Target number they want.
Attachment 169591
after they key in target they will click Refresh and it will count the Balance by OUTPUT - TARGET.
Attachment 169593
Now I want after user click Refresh button , I want to get all the data from 2 data grid view and combine to new data grid view below and I want to insert it to new table in my sql .
How can I move the data from 2 datagridview to 1 datagridview ?
I am thinking if it will work this way:
datagridview_Report = datagridview_OUTPUT.datasource ,datagridview_TARGET.datasource.
really dont know what to do.
Please help me and thank you in advanced.
Attachment 169595
this is related to my question before:
http://www.vbforums.com/showthread.p...alculate-value
Re: How to combine 2 data grid view to one data grid view and insert it to new table
What's the relationship between the data in the two grids? Is it 1:1 based on row index, i.e. the first row of each grid effectively constitutes a single record, etc? Is it parent/child, i.e. each row in the first grid corresponds to zero, one or more rows in the second grid? Something else? Please provide a FULL and CLEAR explanation of the problem.
Re: How to combine 2 data grid view to one data grid view and insert it to new table
Hi Sir,
Here is my methods to calculate the Balance column. I got data from first dgv Output column and Minus it to 2nd dgv Target column.
that's the only relationship they have I think it is called 1:1 based on row index.
Now my problem is I want to combine it to 1 dgv all 5 columns. is that possible ?
Please help me. if not what can you suggest ?
Code:
void calculateTarget_H5()
{
try
{
if (dataGridView_H5.Rows.Count > 0)
{
for (int i = 0; i < dataGridView_H5.Rows.Count; i++)
{
if (dataGridView_H5_1.Rows[i].Cells[0].Value != null)
{
int sum = Convert.ToInt32(dataGridView_H5_1.Rows[i].Cells[0].Value.ToString()) - Convert.ToInt32(dataGridView_H5.Rows[i].Cells[2].Value.ToString());
dataGridView_H5_1.Rows[i].Cells[1].Value = sum.ToString();
}
}
}
}
catch (Exception)
{
MessageBox.Show("Please input all Target", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
Re: How to combine 2 data grid view to one data grid view and insert it to new table
Is there a specific reason that you don't want to just use one grid in the first place?
4 Attachment(s)
Re: How to combine 2 data grid view to one data grid view and insert it to new table
hi Sir,
I try to used 1 grid view but I have problem when I click Load button again it refresh all data in data grid. example :
I click Load button , It query the count of Output from data source with 3 columns only.
Attachment 169599
I click checkbox show target column, it added 2 columns in grid. TARGET & BALANCE. User must key in manually the Target .
Attachment 169601
after key in Target User will click the Load target button to calculate the BALANCE = OUTPUT-TARGET.
Attachment 169603
Now the problem is , I need to click the Load button every 5 minutes to count the output for real time.
when I do that it delete again the data in Target column that the user entered.
Attachment 169605
is there a way if I click Load button it will only refresh the 3 original columns I selected in my query ?
here is my method to load the 3 columns from datasource.
Code:
void H8()
{
try
{
conn.Open();
cmd = new OleDbCommand("SELECT LINE_NO,STATION,COUNT (DISTINCT(MO_SN))AS INPUT from dqc342 " +
"where TEST_DTTM between to_date('" + dtpFrom.Value.ToString("yyyyMMdd 08:00:00") + "','yyyymmdd hh24:mi:ss')and to_date('" + dtpTo.Value.ToString("yyyyMMdd 07:59:59") + "','yyyymmdd hh24:mi:ss')" +
"and station in('RC4','VMI2')" +
"and LINE_NO='H8'GROUP BY LINE_NO,MODEL,SN_TYPE,STATION,PROD_TYPE ORDER BY STATION", conn);
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
dt = new DataTable();
dt.Load(reader);
dataGridView_H8.DataSource = dt;
conn.Close();
reader.Close();
UpdateFont_H8();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
conn.Close();
}
}
Re: How to combine 2 data grid view to one data grid view and insert it to new table
Hi Sir,
Below is the reason why I can't used 1 grid, because I need to refresh every time the 3 original columns from data table and it will affect the new 2 columns I added to key in Target and Calculate Balance.
kindly help me if there is other way to show what I want.
thank you in advanced.
Re: How to combine 2 data grid view to one data grid view and insert it to new table
Quote:
Originally Posted by
BONITO
Below is the reason why I can't used 1 grid, because I need to refresh every time the 3 original columns from data table and it will affect the new 2 columns I added to key in Target and Calculate Balance.
I don't really see how that's a reason. If the data currently in the second grid is relative to the data in the first then surely you would want the data in the second grid to be affected if you change the data in the first, so the fact that it is if you use one grid seems like a good thing.
Re: How to combine 2 data grid view to one data grid view and insert it to new table
Quote:
Originally Posted by
jmcilhinney
I don't really see how that's a reason. If the data currently in the second grid is relative to the data in the first then surely you would want the data in the second grid to be affected if you change the data in the first, so the fact that it is if you use one grid seems like a good thing.
But is there a way not to affect the Target column only if i use 1 grid only ? so that user will not key in always the Target ? I want if load again it will affect the 3 original columns only and the column Balance. but the target must be fix.
if I make 2 grid i can do it. but if only one grid cannot. because it will refresh all the grid.
Re: How to combine 2 data grid view to one data grid view and insert it to new table
Quote:
Originally Posted by
BONITO
But is there a way not to affect the Target column only if i use 1 grid only ? so that user will not key in always the Target ? I want if load again it will affect the 3 original columns only and the column Balance. but the target must be fix.
if I make 2 grid i can do it. but if only one grid cannot. because it will refresh all the grid.
If you populate a DataTable at the start and bind that, then update the existing rows in that DataTable rather than removing the existing rows and adding new ones or creating a whole new DataTable then yes, the other data will remain unaffected.
Re: How to combine 2 data grid view to one data grid view and insert it to new table
Quote:
Originally Posted by
jmcilhinney
If you populate a DataTable at the start and bind that, then update the existing rows in that DataTable rather than removing the existing rows and adding new ones or creating a whole new DataTable then yes, the other data will remain unaffected.
Yes I populate a datatable and bind it to datagridview that consist of 3 columns only then i added 2 columns that is not in datatable, I just add it manually name(TARGET & BALANCE) in Target col user will input qty and in Balance col it will subtract the Target to Input from datatable column.
how can i load it again without affecting the 2 added column if all are located in one grid view ?