|
Hi,
I have a combobox, in which user can select a value from list and can also type the value.
In the 'SelectedIndexChanged' event some code is written.
I dont want to call the 'SelectedIndexChanged' event code when user types some value in combobox, 'SelectedIndexChanged' event should only be called when user selects a value from the list.
I have tried to suppress the 'SelectedIndexChanged' event when user types in something, but not able find some solution.
can someone please help in this?
Thanks in advance
Mahesh
|
|
|
|
|
Does the selectedindex change when the user types data into the text area? Not behaviour I have ever experienced. However try either trapping the keypress/down event or the textchanged event and set a flag that the selected index uses to decide whether to process the event.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hi all
i have a small problem..actually i searched in the forum but i couldnt see the same problem with mine..so here is my problem..i want to have two different color in my datagridview...for example first row will be blue and second one white and third one again blue and 4th one will be white and so on..i used if block and % in it but i couldnt find anything in the intellisense about datagridview color
|
|
|
|
|
Use the oncellpaint event (I think) and query the object to find what row/column is being painted and set the background accordingly.
Note that this fires for each cell that is on display, not the entire data source
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
did you try this:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.BackgroundColor = Color.Red;
if (i % 2 == 0)
{
dataGridView1.BackgroundColor = Color.Blue;
}
}
Qendro
|
|
|
|
|
Surely that just sets the background colour for the whole DataGridView, not for individual rows?
|
|
|
|
|
i tried this and it worked:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
e.CellStyle.BackColor = Color.Red;
if (i % 2 == 0)
{
e.CellStyle.BackColor = Color.Blue;
}
}
}
Qendro
|
|
|
|
|
It might work (if you replace Columns with Rows), but it doesn't look very efficient. Also, you don't need to do this anyway since DataGridView has a built in property that does it for you (AlternatingRowsDefaultCellStyle).
|
|
|
|
|
hi guys
thanks for the reply
i tried qendro's codes but i have a small problem with it also..it works but not as i wished..it works like that : if i have one or 3 rows in datagridview then datagridview's backcolor becomes blue but when i add another row then it turns to white..
u see it is a bit different than i wished.. i want like that first row will be blue and second white and third blue again and fourth will be white again and so on..any other suggestions you have
thanks all for the replies
|
|
|
|
|
|
yeah man u are right
it works now as i wanted
thanks all u for your help
|
|
|
|
|
Hi everybody
I need to write a software that read udp packets with events.
Best Regards,
Reza Shojaee
|
|
|
|
|
This gives you some good looking results[^], sorry not to be more specific
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Dear developers,
I know how to send/receive databytes via serial-port.
How can this be done via USB?
|
|
|
|
|
This depends on the device you are connecting via usb port
|
|
|
|
|
I want to download from i-net some historical stock-market data. Doing this via the i-net-explorer, I navigate to the appropriate site, then I select some parameters and finally I press a button for "download to Spreadsheet".
E.g. see at site: http://finance.yahoo.com/q/hp?s=INTC
No Problem so far, but now I want to automize these steps by a program.
But how can I press a button programatically?
Thanks in advance
modified on Wednesday, January 6, 2010 5:52 AM
|
|
|
|
|
There are plenty of macros Internet tools, e.g. iMacros, you can google for it and find it.
|
|
|
|
|
May be some misunderstanding.
I want to create a WinForms-Applikation which does the job of downloading. But how can this be accomplished if the i-net-site needs some interaction?
|
|
|
|
|
I was not aware if iMacros.
I will read what it is
|
|
|
|
|
Hi All,
Can anyone please clarify my dout about IDisposable intreface in C#.
We all know tat IDisposable interface is using for disposing unmanaged resources.
I have a class which contains following code. here i have implimented the Dispose method from IDisposable interface.
class ClassA:IDisposable
{
public ClassA()
{
Console.WriteLine("ClassBeingTested: Constructor");
}
private bool disposed = false;
Image img = null;
public Image Image
{
get { return img; }
}
~ClassA()
{
Console.WriteLine("ClassBeingTested: Destructor");
// call Dispose with false. Since we're in the
// destructor call, the managed resources will be
// disposed of anyways.
Dispose(false);
}
public void Dispose()
{
Console.WriteLine("ClassBeingTested: Dispose");
// dispose of the managed and unmanaged resources
Dispose(true);
// tell the GC that the Finalize process no longer needs
// to be run for this object.
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposeManagedResources)
{
// process only if mananged and unmanaged resources have
// not been disposed of.
if (!this.disposed)
{
Console.WriteLine("ClassBeingTested: Resources not disposed");
if (disposeManagedResources)
{
Console.WriteLine("ClassBeingTested: Disposing managed resources");
// dispose managed resources
if (img != null)
{
img.Dispose();
img = null;
}
}
// dispose unmanaged resources
Console.WriteLine("ClassBeingTested: Disposing unmanaged resouces");
disposed = true;
}
else
{
Console.WriteLine("ClassBeingTested: Resources already disposed");
}
}
// loading an image
public void LoadImage(string file)
{
Console.WriteLine("ClassBeingTested: LoadImage");
img = Image.FromFile(file);
}
}
What my doubt is why i need to impliment the Dispose method from IDisposable interface?. Instead of that i can create my own Dispose method in my class without inheriting from IDisposable interface which i have given below.
for the class below i haven't inherited my class from IDisposable interface. instead of that i created my own dispose method. this also works fine.
class ClassA
{
public ClassA()
{
Console.WriteLine("ClassBeingTested: Constructor");
}
private bool disposed = false;
Image img = null;
public Image Image
{
get { return img; }
}
~ClassA()
{
Console.WriteLine("ClassBeingTested: Destructor");
// call Dispose with false. Since we're in the
// destructor call, the managed resources will be
// disposed of anyways.
Dispose(false);
}
public void Dispose()
{
Console.WriteLine("ClassBeingTested: Dispose");
// dispose of the managed and unmanaged resources
Dispose(true);
// tell the GC that the Finalize process no longer needs
// to be run for this object.
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposeManagedResources)
{
// process only if mananged and unmanaged resources have
// not been disposed of.
if (!this.disposed)
{
Console.WriteLine("ClassBeingTested: Resources not disposed");
if (disposeManagedResources)
{
Console.WriteLine("ClassBeingTested: Disposing managed resources");
// dispose managed resources
if (img != null)
{
img.Dispose();
img = null;
}
}
// dispose unmanaged resources
Console.WriteLine("ClassBeingTested: Disposing unmanaged resouces");
disposed = true;
}
else
{
Console.WriteLine("ClassBeingTested: Resources already disposed");
}
}
// loading an image
public void LoadImage(string file)
{
Console.WriteLine("ClassBeingTested: LoadImage");
img = Image.FromFile(file);
}
}
So can any one tel me tat the reason behind of implimenting dispose method from IDisposable interface. I think everybody understands my question. i searched in google a lot. but i did not get a proper answer.So please clarify my doubt.
Regards
Lijo
|
|
|
|
|
As you pointed out yourself, it makes sense to implement IDisposable to free up unmanaged resources. Since this class embeds an Image, which is IDisposable, it should itself be disposable. I didn't read all of the lenghty unformatted code you posted, but if that's all there is to it, it would suffice to do this:
public void Dispose()
{
if (img != null) img.Dispose();
}
|
|
|
|
|
Thats fine. There is nothing relevant in my code. Code i have given just for explaining my Problem.
So Can u please tell me why should i inherit my class from IDisposable intreface for implementing dispose method? Here i can write my own Dispose method without inheriting IDisposable intreface which i have shown in my code. Then can u please tell me why microsoft is telling that i have to inherit my class from IDisposable intreface for implimenting dispose method? is there any specific reason behind that?
in my code directly i used img.Dispose();. here i no need to inherit my class from IDisposable intreface.
I think u can understand what i am trying to clarify..
Regards
Lijo
|
|
|
|
|
Once i used interface for a plugin.
If you use unmanaged calss, you need to close window handles and other stuff. The IDisposable interface exsist for GarbageColletor that can properly dispose a class. This apply to automatic Dispose. Not call from a code
|
|
|
|
|
I think u guys did not understand my question. i very well know tat we have to use IDisposable intreface for handiling un managed resources. but we no need to inherit our class from IDisposable intreface for implimenting Dispose method. I can write my own Dispose method. So my question is what is the specific reason behind inheriting our class from IDisposable intreface?
|
|
|
|