shay Avital
Member
- Joined
- Oct 9, 2020
- Messages
- 12
- Programming Experience
- Beginner
i am trying to read a binary file value in a datagridview but i get the following error:
Topshelf.Hosts.ConsoleRunHost Critical: 0 : The service threw an unhandled exception, System.NullReferenceException: Object reference not set to an instance of an object.
here is my code:
the error is on line : Mlist.MeterGrid.Rows.Add();
thanks for your help,
Shay.
Topshelf.Hosts.ConsoleRunHost Critical: 0 : The service threw an unhandled exception, System.NullReferenceException: Object reference not set to an instance of an object.
here is my code:
C#:
string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"c:\qlcservice\grid.bin");
using (BinaryReader bw = new BinaryReader(File.Open(file, FileMode.Open)))
{
int n = bw.ReadInt32();
int m = bw.ReadInt32();
for (int i = 0; i < m; ++i)
{
Mlist.MeterGrid.Rows.Add();
for (int j = 0; j < n; ++j)
{
if (bw.ReadBoolean())
{
Mlist.MeterGrid.Rows[i].Cells[j].Value = bw.ReadString();
}
else bw.ReadBoolean();
}
}
}
thanks for your help,
Shay.