|
dabuskol wrote: localDS = (DataSet)Cache["listTables"];
You have not checked if the cache is still valid.
dabuskol wrote: DataView dv = new DataView(localDS.Tables[1]); --- Failed on this part
Are you sure the dataset have at least 2 tables, on every call?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Definitely yes, before assigning it to cache the Dataset (DS) has four tables, after assigning to cache object I can still see the 4 tables. But only after pressing the 2nd dropdownlist with postback where data should come from cache object instead of database the value of cache is null.
Dabsukol
|
|
|
|
|
That is quite interesting. You not running out of memory for caching perhaps?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Nop. I just change the CACHE to ViewState Object and it work.
Though I believe Viewstate is not the solution since I have 10 dropdownlist in every page. Viewstate will make my page heavy becuase of the encrypted data.
I tried to search the Net and I can't find any solution to this problem
Dabsukol
|
|
|
|
|
It's normal for contents to get removed from the cache. When you get the value from the cache you have to check if you get a null reference back.
If the cache grows too much, it will naturally remove large objects first. Perhaps your objects will stay longer in the cache if you store the tables as four separate cache objects.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for all the help.
After so many trials and isolation, the only problem I believe that is missing why the data on the CACHE object is missing si the declaration of the namespace of CACHE.
using System.Web.Caching --- After including it in my code. it works perfect.
Dabsukol
|
|
|
|
|
Hello,
I'm looking for a way to solve follwing type of problem (this is a simplified example) in a C# environment
Lets say I have a booking tool for multiple medias.
I have one method:
- addBooking()
Two media types:
- Radio
- Web
I would like to have additional logic in my addBooking method depending the media type; that means:
addBooking() does the same functionality,but , if I have radio I want to add special discount and if I have web I want to edit some other booking.
I read about "software extension" which is, I think, what I need. How can I implement that? I thought of some kind of listener after my addBooking() which checks the media type and calls the right method depending the type.
Thanks for any ideas!
|
|
|
|
|
I would use an abstract class which implemented the base method, e.g.
public abstract MediaBase
{
public virtual void AddBooking()
{
}
} Then, inherit from this class, e.g.
public Radio : MediaBase
{
}
public Web : MediaBase
{
public overrides void AddBooking()
{
base.AddBooking();
}
}
|
|
|
|
|
That's a good and simple idea.
The only thing is that I need to instanciate either a Radio or Web object in the application.
I would like to call mediaBase.AddBooking() and that's it. Then, from an external controler, acting like a listener, run the custom code depending of the media type (media type is a static configuration at application launch).
|
|
|
|
|
OK - this sounds like a case for using the Inversion of Control and Dependency Injection patterns. This sounds like an ideal candidate.
|
|
|
|
|
Took a look at it, that's a good solution, thanks for help!
|
|
|
|
|
|
If I create a program in c# with multiple threads,
does the OS automatically spread them over the available cores?
Or is the app just divided in some time slices on a single core?
|
|
|
|
|
Yes, If you create and execute multiple threads, the OS will run each thread on whatever CPU it thinks will give the best performance to that thread.
Simon
|
|
|
|
|
Hello,
Could someone tell me if its possible to create a OLE Server using C#? I want to be able to insert documents from the C# into other applications using the "Insert Object" method.
Many Thanks
|
|
|
|
|
|
I have a regular System.Windows.Forms.ComboBox. This control listens to OnDrawItem(DrawItemEventArgs ea) events. How can I programmatically generate this event for an arbitrary item in the ComboBox? Thanks for any help.
|
|
|
|
|
arnold_w wrote: I have a regular System.Windows.Forms.ComboBox. This control listens to OnDrawItem(DrawItemEventArgs ea) events.
I think you have misunderstood events. The combo box triggers DrawItem events. Your code listens to them.
You can attach a listener using the += construct, like this
private void CreateComboBox()
{
ComboBox cbox = new ComboBox();
this.Controls.Add(cbox);
cbox.DrawItem += new DrawItemEventHandler(cbox_DrawItem);
}
void cbox_DrawItem(object sender, DrawItemEventArgs e)
{
}
Be careful not to attach listeners multiple times. Once attached, the listener will continue to respond to the event every time it is triggered until you detach it, or the object is destroyed.
Simon
|
|
|
|
|
Thanks for your reply. Ooops, sorry. Of course, you are correct. I shouldn't write posts early in the morning What I mean is that I have inherited the ComboBox and have overridden the OnDrawItem method:
public SpecialComboBox() : ComboBox
{
protected override void OnDrawItem(DrawItemEventArgs ea)
{
}
}
I want the OnDrawItem to be executed at my request. Of course, I can simply call the OnDrawItem method, but if I do I don't know how to determine the DrawItemEventArgs argument. Therefore, I would like to make it be executed "automatically". Is there something I can do, for example, to invalidate the control, call Refresh on the control, etc to force this event to be generated?
|
|
|
|
|
You need to set combobox.DrawMode = DrawMode.OwnerDrawFixed
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Ahh, I see what you're trying to do.
You shouldn't really be calling OnDrawItem yourself. The idea is that the method is called automatically whenever windows needs to draw the item. You then intercept that with your override and perform the customised drawing.
Like Leppie says, you need to enable owner drawing for the method to be triggers. This bit of sample code draws the items in red.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CreateComboBox();
}
private void CreateComboBox()
{
MyCombo cbox = new MyCombo();
cbox.DrawMode = DrawMode.OwnerDrawFixed;
cbox.Items.Add("test1");
cbox.Items.Add("test2");
this.Controls.Add(cbox);
}
}
public class MyCombo : ComboBox
{
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
String item = (String)this.Items[e.Index];
Debug.WriteLine("drawing: " + item);
e.Graphics.DrawString(item, e.Font, Brushes.Red, e.Bounds.Location);
base.OnDrawItem(e);
}
}
(Set it to fixed or variable, depending on the type of custom drawing you plan on doing)
Simon
|
|
|
|
|
Thank you both you for your suggestions, but I'm still unsure how I can use it in my application. This is basically what I need:
public SpecialComboBox() : ComboBox
{
protected override void OnDrawItem(DrawItemEventArgs ea)
{
}
private void MakeWindowsThinkItNeedsToDrawAnItem(int item)
{
}
}
Is it possible to implement the MakeWindowsThinkItNeedsToDrawAnItem method?
|
|
|
|
|
I think you may have a design issue here. Why do you want to make windows think it needs to draw an item?
You only want to execute the drawing code, when you actually need the item drawn.
If you need it called at some other time, I would suggest that you possibly have code in the OnDrawItem method that shouldn't really be there.
Simon
|
|
|
|
|
Again, thanks for your input. The reason I want to be able to make Windows think it needs to draw an item is that I want to be able to switch color of an item at any given moment.
|
|
|
|
|
In that case, just call Invalidate, the Draw methods will be called again, and you can paint your changes. Sometimes, Invalidate is not enough, the you can fall back to Refresh.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|