|
Hello All ,
I have used a CalendarExtender in my page with textboxes. When I press enter key in another textbox, calendar's popup is appearing.
I have used defaultbutton attribute in form tag and tried keeping my button id as defalut button but this is also not working.
Please help me out in same..
Thanks In Advance
|
|
|
|
|
Smells like ASP.Net to me. You will get better responses in that forum.
|
|
|
|
|
Hi guys,
I need to find a way around a problem so that I can have an array containing lists of different types, where those types are all derived from the same class. Unfortunately I'm at the end of my knowledge of covariance etc so any help would be greatly appreciated.
To explain better:
I have a class ('class X') which has several lists in it. The lists contain different types, but these types all derive from the same abstract class. I need to be able to iterate through all items (i.e. across and within the lists) as though all the lists were one. For various reasons, the lists must remain as separate objects. Furthermore, 'Class X' is inherited, and derived classes have additional lists...
My solution was to create an array containing these lists (which makes iterating with an unknown number of lists very easy), but I hit problems very quickly (e.g. see code below). Can anyone show me how to do something like this, or find a more elegant way to do it?
Here's a much smaller, simple example of the kind of thing I'm trying to do:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
abstract class A
{ }
class B : A
{ }
class C : A
{ }
class ClassX
{
static void DoStuff()
{
List<B> listB = new List<B>();
List<C> listC = new List<C>();
List<A>[] arrayOfLists = new List<A>[2];
arrayOfLists[0] = listB;
arrayOfLists[1] = listC;
arrayOfLists[0] = listB.Cast<A>().ToList();
List<List<A>> listOfLists = new List<List<A>>();
listOfLists.Add(listB);
}
}
}
Thanks!
Lee
|
|
|
|
|
The List(T) class is neither covariant nor contravariant.
Here is why:
If you have a list of class A, you can't cast it to a list of class B (derived from A), because not all instances of class A are also instances of class B. This is obvious.
Now the other way: why is it impossible to cast a list of clas B (derived from A) to a list of class A? Because then you could add an item of class C (derived from A) to the list, although it is actually a list of B.
If you only need to iterate throught all the items (thus the full list can be read-only), then you can create a custom iteration logic by implementing the IEnumerable(T) and IEnumerator(T) interfaces, that's probably what I would do... Instead of adding a new List(A) to the class, create a method that returns IEnumerable(A) and implement the iteration logic.
|
|
|
|
|
Hey Kubajzz, thanks for your reply.
I understand what you've said. Problem is that kind of jump-to-the-next-list iteration logic makes the whole thing very messy when the List<B>, List<C>, etc lists are not in some sort of collection (i.e. where it is obvious as to which list to jump to without needing special programming).
It also raises the problem that every class that subsequently derives from 'ClassX' requires a decent amount of overriding/patching if they add new lists (e.g. List<D>, List<E>). My project has several deriving classes, and values being entirely 'readonly' defeats the purpose of the whole class
Is there not an easy way to collect these lists together in some sort of collection?
Thanks heaps for your time
<div class="modified">modified on Monday, September 6, 2010 6:52 AM</div>
|
|
|
|
|
Lee Reid wrote: My project has several deriving classes, and values being entirely 'readonly' defeats the purpose of the whole class
I thought you only needed the complete list for iterating through all lists, thus a read-only iterator (such as IEnumerator) could be enough.
IEnumerable(T) can be implemented in a very clean way without the need of any "special programming".
See the following example:
class A {}
class B : A {}
class C : A {}
class MyClass {
private List<B> listB;
private List<C> listC;
public MyClass() {
}
public IEnumerable<A> GetAllItems() {
IEnumerable<A> b = listB;
IEnumerable<A> c = listC;
return b.Concat(c);
}
}
Yes, it is this simple. Note that the GetAllItems method could easily be 1-line long. You can implement some logic to get all the lists in the current class as an array of IEnumerable<A> for easy overriding, it's not more than 1 or 2 very short methods... I don't think this is messy, nor does it require any "special programming" and I highly doubt there is easier and simpler solution.
The one and only question is: does IEnumerable provide enough functionality for your application?
|
|
|
|
|
Absolutely perfect!
Thank you so much; I've not used ienumerable and related interfaces before, and didn't realise quite how elegant/easy/functional they could be. You've relieved quite a headache of mine!
Thanks again
|
|
|
|
|
I'm glad it helped...
Here are 2 more notes to make my answer a bit more complete. I assume you aready know all this, but it coud be useful to someone:
- The System.Linq namespace is your best friend when working with IEnumerable(T).
- The yield return statement is an awesome language feature... http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx
|
|
|
|
|
As has been explained, it can't be done with an implicit or explicit cast.
Here is a little method to do it for you.
public static List<TBase> DerivedConverter<TBase, TDerived>(List<TDerived> derivedList)
where TDerived : TBase
{
return derivedList.ConvertAll<TBase>(
new Converter<TDerived, TBase>(delegate(TDerived derived)
{
return derived;
}));
}
To use:
List<Base> listBase = DerivedConverter<Base, Derived>(listDerived);
where Base is the base class and Derived is a class derived from Base .
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
Sort of. The item references are copied so any changes to an element in listB will be reflected in listA .
Test Code:
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
Derived derived1 = new Derived(1);
Derived derived2 = new Derived(2);
List<Derived> listDerived = new List<Derived>(new Derived[] { derived1, derived2 });
List<Base> listBase = DerivedConverter<Base, Derived>(listDerived);
listDerived[0].ID = 0;
for (int i = 0; i < listBase.Count; i++)
{
Console.WriteLine("{0} {1}",
object.ReferenceEquals(listBase[i], listDerived[i]),
listBase[i].ID);
}
Console.ReadKey();
}
public static List<TBase> DerivedConverter<TBase, TDerived>(List<TDerived> derivedList)
where TDerived : TBase
{
return derivedList.ConvertAll<TBase>(
new Converter<TDerived, TBase>(delegate(TDerived derived)
{
return derived;
}));
}
}
public class Base
{
public Base(int id)
{
ID = id;
}
public int ID { get; set; }
}
public class Derived : Base
{
public Derived(int id)
: base(id)
{ }
}
If you add or remove items to listB then that won't be reflected in listA unless you rebuild it dynamically.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Perhaps something like this will help. This implementation doesn't allow you to add items to the base list, I don't know if that is a requirement or not. This won't be particularly efficient but should work (untested!). You would need to add checks to make sure the lists aren't null too.
public class BaseList<TBase, TDerived1, TDerived2>
where TDerived1 : TBase
where TDerived2 : TBase
{
private List<TDerived1> derived1List;
private List<TDerived2> derived2List;
public List<TDerived1> Derived1List
{
get { return derived1List; }
set { derived1List = value; }
}
public List<TDerived2> Derived2List
{
get { return derived2List; }
set { derived2List = value; }
}
public ReadOnlyCollection<TBase> BaseCollection
{
get
{
List<TBase> baseList = DerivedConverter<TBase, TDerived1>(derived1List);
baseList.AddRange(DerivedConverter<TBase, TDerived2>(derived2List));
return baseList.AsReadOnly();
}
}
private static List<TBase> DerivedConverter<TBase, TDerived>(List<TDerived> derivedList)
where TDerived : TBase
{
return derivedList.ConvertAll<TBase>(
new Converter<TDerived, TBase>(delegate(TDerived derived)
{
return derived;
}));
}
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks Dave!
while not being the 'perfect' solution, you seem to have inadvertently solved another problem of mine, which I hadn't put to the forums yet!
I appreciate the help
|
|
|
|
|
You're welcome
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
Would this help?
public static System.Collections.Generic.IEnumerable<T>
Enumerate<T>
(
params System.Collections.Generic.IEnumerable<T>[] Lists
)
{
foreach
(
System.Collections.Generic.IEnumerable<T> list
in
Lists
)
{
foreach
(
T t
in
list
)
{
yield return ( t ) ;
}
}
yield break ;
}
|
|
|
|
|
I wrote an application that outlook 2003 in C#, but I don't know how to deploy it? Who can help me?
|
|
|
|
|
Ok ill start by saying I am new to c# what i am trying to do is basicly access a ultralite db it has a table named Names(name,chan,freq,mpchan) I want to populate a combox with name field than have 3 text fields populate with the appropriate data for the name selection. Here is what i got so far
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using iAnywhere.Data.UltraLite;
using System.Collections;
namespace ChannMap
{
public partial class Form1 : Form
{
private string strChan;
private string strFreq;
private string strName;
private string strMapChan;
private string strTemp;
private string [] strArraylist=new string [1000];
static int i = 0;
private ULConnection ConnUL = new ULConnection();
private ULDataAdapter myDataAdapter = new ULDataAdapter();
private void Form1_Load(object sender, System.EventArgs e)
{
fnGetConnectedToDatabase();
}
public Form1()
{
InitializeComponent();
}
private void fnGetConnectedToDatabase()
{
try
{
String dbf = "\\Program Files\\ChannMap\\ChannMap.udb";
if (System.IO.File.Exists(dbf))
{
ConnUL.ConnectionString = "dbf=" + dbf + ";cache_size=1M";
if (ConnUL.State != ConnectionState.Open)
{
ConnUL.Open();
}
ConnUL.DatabaseID = 1000;
}
else
{
MessageBox.Show("Database is not available", "Error");
Application.Exit();
}
}
catch (System.Exception t)
{
MessageBox.Show(t.Message, "Connection failed");
return;
}
string sqlStr = "SELECT * FROM Names;";
myDataAdapter = new ULDataAdapter(sqlStr,ConnUL);
DataSet myDataset = new DataSet();
myDataset.Clear();
myDataAdapter.Fill(myDataset,"Names");
foreach (DataRow myRow in myDataset.Tables["Names"].Rows)
{
strChan =(string) myRow["chan"];
strFreq = (string)myRow["freq"];
strMapChan=(string) myRow["mpchan"];
strName=(string) myRow["name"];
strTemp=strChan+"*"+strFreq+"*"+strMapChan+"*"+strName;
strArraylist[i++]=strTemp;
comboChanName.Items.Add(strName);
}
ConnUL.Close();
}
private void comboChanName_SelectedIndexChanged(object sender, System.EventArgs e)
{
string delimstr = "*";
char [] delimeter = delimstr.ToCharArray();
string [] splitstr = null;
splitstr = strArraylist[this.comboChanName.SelectedIndex].Split(delimstr, 4);
textBox1.Text = splitstr[0];
textBox2.Text = splitstr[1];
textBox3.Text = splitstr[2];
textBox4.Text = splitstr[3];
}
}
}
splitstr = strArraylist[this.comboChanName.SelectedIndex].Split(delimstr, 4);
this piece when i try to deploy gives the error cannot convert char[] to char and cannot convert int to char. This a mobile app to. Am I going about this the hard way is there a better way or can this code be fixed?
Thank you for any help
Aaron
|
|
|
|
|
I did't read the whole code, but I can see a problem in the way you use the String.Split method.
splitstr = strArraylist[this.comboChanName.SelectedIndex].Split(delimstr, 4);
This won't compile because it is not a valid overload. You should use delimeter instead of delimstr as the first parameter... See the complete list of String.Split overloads.
|
|
|
|
|
Didnt seem to have an effect when changed
|
|
|
|
|
Ok. I will try to ignore the fact that you provided way too much code that seems very cryptic and unreadable, while only about 10 lines are related to the error... I will ignore the fact that most of the infrotmation you provided with your code is absolutely useless and irrelevant. I will ignore the fact that the title of your first post is the second worst possible title (the first one being "PLZ HELP URGNT"). And I will also try to ignore the fact that your last post didn't contain that mysterious word starting with "tha" and ending with "nks"...
If my previous advice didn't help, there is not much more I can do for you. The best help I can give you is:
Read the compiler error carefully. Locate the problem in your code. Check everything on that line, see what parameters are required for each method... And then make sure that the parameters you are passing match the required type.
With intellisense and all the support provided by Visual Studio (or whatever tool you use) it should not take more than 23.7865039 seconds to locate and fix such a simple error like a type mismatch... even if you are a beginner!
|
|
|
|
|
I have been using Visual C++ Remote Debugger for debugging native code for some years, and it does not require Windows authentication. This is my first time doing C# things. I learned that remote debugging C# managed code requires Windows authentication.
The laptop with Visual Studio 2008 Pro (the host machine, Windows XP) is in my company domain, whereas the target machine (Windows 7) is of some WORKGROUP not in my company domain.
I have tried various configurations according to this MSDN doc[^] and this article[^], including the below:
- Setting up the identical account/password (of admins group) in both the host and the target machine,
- Turning off Windows Firewall,
- Turning on Windows Firewall with proper exceptions,
- Using "runas" to launch VS2008 with some specific user account,
- Enabling all ICMP responses,
- Adding my domain user account to the "Run as Service" in the Local Security Policy of the target machine,
etc.
Nothing makes it work. The symptom is as this screenshot[^]. Sometimes with certain configuration it said "Access is denied" in the end of the popup message.
Have anyone had the same experience? How did you resolve the issue?
Thanks in advance.
Maxwell Chen
|
|
|
|
|
Hi,
I'm not very good at RegEx , I want to use RegEx class to match values with desired string. My main string looks like this:
<%#String.Concat ..blah blah.. %>
in above string I want to get all the matches which between double quotes ( " ... " ) in blah blah part.
What is my expression should look like?
Thanks for your help
Mazy
"This chancy chancy chancy world."
|
|
|
|
|
you should post in no more than one location (a single forum, or Q&A) so everything about this topic stays together.
|
|
|
|
|
What do you have so far?
Also see my RegEx tester[^] and Expresso.
Edit: I coulda sworn I replied in the RegEx forum!
modified on Sunday, September 5, 2010 11:41 PM
|
|
|
|
|