|
-
Jul 2nd, 2019, 10:32 PM
#1
Thread Starter
Lively Member
-
Jul 2nd, 2019, 11:11 PM
#2
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.
-
Jul 2nd, 2019, 11:25 PM
#3
Thread Starter
Lively Member
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);
}
}
-
Jul 3rd, 2019, 12:49 AM
#4
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?
-
Jul 3rd, 2019, 04:03 AM
#5
Thread Starter
Lively Member
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.

I click checkbox show target column, it added 2 columns in grid. TARGET & BALANCE. User must key in manually the Target .

after key in Target User will click the Load target button to calculate the BALANCE = OUTPUT-TARGET.

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.

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();
}
}
-
Jul 3rd, 2019, 08:07 PM
#6
Thread Starter
Lively Member
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.
-
Jul 3rd, 2019, 09:25 PM
#7
Re: How to combine 2 data grid view to one data grid view and insert it to new table
 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.
-
Jul 3rd, 2019, 10:46 PM
#8
Thread Starter
Lively Member
Re: How to combine 2 data grid view to one data grid view and insert it to new table
 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.
Last edited by BONITO; Jul 3rd, 2019 at 10:51 PM.
-
Jul 3rd, 2019, 11:12 PM
#9
Re: How to combine 2 data grid view to one data grid view and insert it to new table
 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.
-
Jul 3rd, 2019, 11:27 PM
#10
Thread Starter
Lively Member
Re: How to combine 2 data grid view to one data grid view and insert it to new table
 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 ?
Last edited by BONITO; Jul 4th, 2019 at 01:54 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|