You first have to think about the problem without displaying the data, after solved use Datagridview only for display.
I made a small example, I hope it helps to understand the problem:
First you need to define an object of your Notafiscal:
public class NotaFiscal
{
public string Chave {get;set;}
public string Emitente {get;set;}
public decimal Total {get;set;}
}
Then you will get the data in this format, no matter if it comes from the database, excel, or other source:
public static List<NotaFiscal> GetNotasExcel()
{
List<NotaFiscal> notas = new List<NotaFiscal>();
notas.Add(new NotaFiscal(){ Chave = "123456ABC", Emitente = "Empresa A", Total = 10 });
notas.Add(new NotaFiscal(){ Chave = "223456DEF", Emitente = "Empresa B", Total = 20 });
notas.Add(new NotaFiscal(){ Chave = "423456JKL", Emitente = "Empresa D", Total = 40 });
notas.Add(new NotaFiscal(){ Chave = "623456PQR", Emitente = "Empresa F", Total = 60 });
notas.Add(new NotaFiscal(){ Chave = "723456STU", Emitente = "Empresa G", Total = 70 });
notas.Add(new NotaFiscal(){ Chave = "823456VWX", Emitente = "Empresa H", Total = 80 });
return notas;
}
public static List<NotaFiscal> GetNotasConsisaNet()
{
List<NotaFiscal> notas = new List<NotaFiscal>();
notas.Add(new NotaFiscal(){ Chave = "123456ABC", Emitente = "Empresa A", Total = 10 });
notas.Add(new NotaFiscal(){ Chave = "223456DEF", Emitente = "Empresa B", Total = 20 });
notas.Add(new NotaFiscal(){ Chave = "323456GHI", Emitente = "Empresa C", Total = 30 });
notas.Add(new NotaFiscal(){ Chave = "423456JKL", Emitente = "Empresa D", Total = 40 });
notas.Add(new NotaFiscal(){ Chave = "523456MNO", Emitente = "Empresa E", Total = 50 });
notas.Add(new NotaFiscal(){ Chave = "623456PQR", Emitente = "Empresa F", Total = 60 });
notas.Add(new NotaFiscal(){ Chave = "723456STU", Emitente = "Empresa G", Total = 70 });
notas.Add(new NotaFiscal(){ Chave = "823456VWX", Emitente = "Empresa H", Total = 80 });
return notas;
}
Then you store the data in lists, so you can work with them:
List<NotaFiscal> notasExcel = GetNotasExcel();
List<NotaFiscal> notasConsisaNet = GetNotasConsisaNet();
Now you can find the data in any condition you want. Taking advantage of your case, I made an example to select all the notes that are in the "Consisanet" and are not in the Excel file:
List<string> chavesExcept = notasConsisaNet.Select(x => x.Chave).Except(notasExcel.Select(x=>x.Chave)).ToList();
Note that I had to select all keys (string) to compare with the keys in the other list. This is because, if you compare two objects they will be compared by the instance, then even if the data are equal, they are different instances and would not be returned in this clause.
With the key list, you can now select the desired notes (if necessary):
List<NotaFiscal> notasExcept = notasConsisaNet.Where(x => chavesExcept.Contains(x.Chave)).ToList();
Ready! You already have all the data you need in memory. Just display them:
dataGridViewExcept.DataSource = notasExcept;
dataGridViewNotasExcel.DataSource = notasExcel;
dataGridViewNotasConsisa.DataSource = notasConsisaNet;
I made an example at .Netfiddle
I hope it will help solve the problem. I recommend that you access and read the Tour, because it is important to know how to participate in the community and to elaborate the questions. You can still improve your question by making it more specific and clear, thus gaining reputation and usually the negative votes are withdrawn.
not related to the question but, what are you using for this interface of datagridview ? thank you
– Rovann Linhalis
Sincerely nothing. I just altered your properties.
– Jehan Kheller
this is not the standard look of the control, so the question, is not using any external component for this ?
– Rovann Linhalis
Yes, this is the standard Datagridview control, all I did was edit its properties. If you want, I can make it available for download.
– Jehan Kheller
was pretty cool, don’t worry the curiosity was to know if it was something external even. Thank you
– Rovann Linhalis
Thank you. It’s really important for me to get every possible feedback on my project.
– Jehan Kheller
About my problem, would you have any solution? Honestly, I don’t know what I do.
– Jehan Kheller
Make the logic in the classes, use datagridview only to display. Put the class you use to the notes I try to help you... I’m running out of time, but I’ll try
– Rovann Linhalis
The problem is that these Grids receive data directly from an excel spreadsheet. Only the second Grid uses a class to better organize the data. So I try to do the analysis directly in Datagridview’s. I thought about doing this using Lists, because there is a Method called Except. But I did not study in depth how it works.
– Jehan Kheller
The first step is to create the classes that represent the lines, then work with the lists. Shows the code that you populate the grids
– Rovann Linhalis
Follow the link: https://drive.google.com/file/d/1KT1br1pIgwWvdGTar_vHfDV89ssrO9XE/view?usp=sharing
– Jehan Kheller