how can i compare data with datagrid in c# ?
is this a looping question?
<loop through everything> if RecID does not exist in LEFT but exists in RIGHT add new item to LEFT if RecID does exist in LEFT but does not exist in RIGHT delete item from LEFT if RecID does exist in LEFT and also exists in RIGHT, check each cell in row and update LEFT.. i can handle this part <end loop>
'Add new items (alert) For Each dr As DataRow In alertTableNew.Rows() Dim found As Integer = -1 For Each gr As DataGridViewRow In DataGridView1.Rows() If dr.Item("RecID") = gr.Cells("RecID").Value Then found = dr.Item("RecID") gr.Cells("status").Value = dr.Item("status") 'status may change, update it here End If If found = -1 Then DataGridView1.Rows.Add( _ dr.Item("line"), _ dr.Item("acct"), _ dr.Item("alarmdescription"), _ dr.Item("status"), _ dr.Item("name"), _ dr.Item("RecID")) End If Next Next 'Remove expired items (alert) For Each gr As DataGridViewRow In DataGridView1.Rows() Dim found As Integer = -1 For Each dr As DataRow In alertTableNew.Rows() If Not gr Is Nothing And gr.Cells("RecID").Value = dr.Item("RecID") Then found = dr.Item("RecID") gr.Cells("status").Value = dr.Item("status") 'status may change, update it here End If If found = -1 Then DataGridView1.Rows().Remove(gr) End If Next Next
thank you so!, but uhmm, do you know how to compare data with listbox? is just that im not very familiar with datagrid ! :S
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { this.textBox1.Text = this.listBox1.SelectedValue.ToString(); if (listBox1.SelectedItem.Equals("Gearbox")) { string con = @"Server=(local);user id=sa;password=;database=TurnShop"; string qry = @"select * from Manufacturer where Product_type ='Gearbox'"; SqlDataAdapter cmd = new SqlDataAdapter(qry, con); DataSet ds = new DataSet(); cmd.Fill(ds, "Manufacturer"); this.dataGridView1.DataSource = ds; } else if (listBox1.SelectedItem.Equals("Brakes")) { string con = @"Server=(local);user id=sa;password=;database=TurnShop"; string qry = @"select * from Manufacturer where Product_type ='Brakes'"; SqlDataAdapter cmd = new SqlDataAdapter(qry, con); DataSet ds = new DataSet(); cmd.Fill(ds, "Manufacturer"); this.dataGridView1.DataSource = ds; } } This might solve your problem.
Might Solve
Join our real-time social learning platform and learn together with your friends!