By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,982 Members | 1,114 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,982 IT Pros & Developers. It's quick & easy.

Is something wrong with datagrid.rows.clear()?

P: n/a
Here's my code. When i try to call it from serialport.DataReceived event i
got random errors. One of them is that object reference is not set to an
instance of an object : in Application.Run(new Form1()) <- I don;t know even
why here. Like program wants to start again.

Anyway Rows.Clear() seems to cause the errors.
public void Fill_DataGrid()
{
ArrayList list = configFile.loadAllValues();

if (list != null)
{
string b = null, pat = null ;

dataGridView1.Rows.Clear();

foreach (String var in list)
{
b = var.Substring(0, var.IndexOf(' '));
pat = var.Substring(var.IndexOf(' '),
var.IndexOf("<p>") - var.IndexOf(' '));

if (var.Contains("."))
{
pat = Path.GetFileName(pat);
pat += " " + var.Substring(var.IndexOf("<p>") + 3);
}

int p = dataGridView1.Rows.Add();
dataGridView1.Rows[p].Cells[0].Value = b;
dataGridView1.Rows[p].Cells[1].Value = pat;
}
}

}
For any help really really thanks
Piotr
May 21 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"PiotrKolodziej" <pi*************@gmail.com> wrote in message
news:35***************************@news.chello.pl. ..
Here's my code. When i try to call it from serialport.DataReceived event i
got random errors. One of them is that object reference is not set to an
instance of an object : in Application.Run(new Form1()) <- I don;t know
even why here. Like program wants to start again.

....

Check:
http://msdn2.microsoft.com/en-us/lib...areceived.aspx

under remarks section... You may access UI elements only from main thread,
but datareceived evnet is raised from secondaty thread.

Goran

May 21 '06 #2

P: n/a
Then maybe you will help me to create Delegate for Datagird.rows.Clear()?

I tried to create delegate in this way

public Delegate myDelegate(object ob1);

i got

Error 1 'IRDAcontrol.Form1.myDelegate(object)' must declare a body because
it is not marked abstract or extern C:\Documents and Settings\test\My
Documents\Visual Studio 2005\Projects\IRDAcontrol\IRDAcontrol\Form1.cs 225
25 IRDAcontrol
If i succed i can try

myDelegate a = myDelegate(dataGridView1.Rows.Clear());

and then use

datagrid.invoke(a)
Am i right?
May 21 '06 #3

P: n/a
PiotrKolodziej wrote:
Then maybe you will help me to create Delegate for Datagird.rows.Clear()?

I tried to create delegate in this way

public Delegate myDelegate(object ob1);
Change "Delegate" to "delegate" and add "void" as data type.

As the compiler doesn't recognise "Delegate" as a keyword, it assumes
that it is the data type of the return value from the method.
i got

Error 1 'IRDAcontrol.Form1.myDelegate(object)' must declare a body because
it is not marked abstract or extern C:\Documents and Settings\test\My
Documents\Visual Studio 2005\Projects\IRDAcontrol\IRDAcontrol\Form1.cs 225
25 IRDAcontrol
If i succed i can try

myDelegate a = myDelegate(dataGridView1.Rows.Clear());

and then use

datagrid.invoke(a)
Am i right?

May 21 '06 #4

P: n/a
> As the compiler doesn't recognise "Delegate" as a keyword, it assumes that
it is the data type of the return value from the method.


What should i write instead of:

myDelegate a = myDelegate(dataGridView1.Rows.Clear());

It asks me for methodname.....
Anyway you have been very helpful and thanks a lot.

Piotr
May 21 '06 #5

P: n/a
On Mon, 22 May 2006 00:48:27 +0200, "PiotrKolodziej"
<pi*************@gmail.com> wrote:
As the compiler doesn't recognise "Delegate" as a keyword, it assumes that
it is the data type of the return value from the method.


What should i write instead of:

myDelegate a = myDelegate(dataGridView1.Rows.Clear());

It asks me for methodname.....
Anyway you have been very helpful and thanks a lot.

Piotr

Hi Piotr

You should replace

dataGridView1.Rows.Clear()

in the line

myDelegate a = myDelegate(dataGridView1.Rows.Clear());

with a method you have created yourself and add the new keyword, e.g

private void ClearReplacementFunc()
{
// do stuff
}

the line of code would then look like

myDelegate a = new myDelegate(ClearReplacementFunc);
hope this helps

Steve

http://www.pretty-vacant.co.uk
May 22 '06 #6

P: n/a
Ill try - Thank you
May 22 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.