|
Why not use the CheckedListBox control instead?
Last modified: 13mins after originally posted --
|
|
|
|
|
there are 4 colums in the list view i want to show checkbox in last column
|
|
|
|
|
Then, why not use DataGridView with the column you want DataGridViewCheckBoxColumn type?
|
|
|
|
|
How do I make an installation program for multiple applications?
I have two windows applications, one web application and a database that I want to install.
I want them all in the same installationprogram. And the user should be able to choose which of the applications to install.
Additionally I want a license verification thru a webservice in the installation program. The webservice will validate the license key and download a license file when the correct license key is submitted. This license file must exist for the applications to run.
I have been looking at WIX to accomplish this but have some problems with accessing some variables when I want to change an already made installation. While using WIX I also only get one entry in “Add or remove programs”.
Since I’m not really satisfied with WIX I been thinking of writing my own userinterface and call separate MSI files made for each application. But I’m not sure if this is the right approach.
Is this the right way to do it and if not how do I accomplish this?
|
|
|
|
|
|
OK - new to generics (very...)
I have a DataTable which contains the data and I want to create classes that visually represent this data in different ways. Eg, a CheckBoxList and a ListBox.
So, hitting the keyboard I come up with :-
public class MyCheckBox : CheckBoxList
{
private BLL.myData _theData;
public MyCheckBox(BLL.myData theData)
{
_theData = theData;
DataSource = _theData.GetDataTable();
DataValueField = "code";
DataTextField = "desc";
DataBind();
}
}
public class MyListBox : ListBox
{
private BLL.myData _theData;
public MyListBox(BLL.myData theData)
{
_theData = theData;
DataSource = _theData.GetDataTable();
DataValueField = "code";
DataTextField = "desc";
DataBind();
}
}
In the front end (web) I can simply add an instance of these to the page and the databinding is taken care of. Cool. But...the code is identical in both classes apart from the derived class type, and the name I've given it.
How would I define a generic class which I can instantiate with the derived type?
I understand how to write generic classes which contain the <t> type, eg
(from memory...)
public class MyStack<T>
{
T[] arrayofMyThings;
}
but not how to create an instance of the <t> type - if that makes sense.?
Regards
Angel
*********************************************
|
|
|
|
|
If by CheckBoxList you mean CheckedListBox , then a common ancester of it and ListBox is ListControl , so make a base class that derives from ListControl and derive from that.
|
|
|
|
|
I may be being very thick here, so stay with me...
...I derive a class (MyListControl) from ListControl, add my databinding etc. No problem.
How do I go from here to get a CheckedListBox and a ListBox which derives from MyListControl and not ListControl.
When you paste the blindingly simple and obvious answer I will most probably take Christian Grauss' suggestion of buying a large book on VB and smashing myself in the face with it.
Regards
Angel
*********************************************
|
|
|
|
|
You can't change the ancestors of existing classes (Without rewriting them), but with a little extra work, you could encapsulate them into a host control.
public class GenericListBox<T> : Control
where T : ListControl
{
public GenericListBox(data...)
{
T innerControl;
if (typeof(T) == typeof(MyListBox))
innerControl = new MyListBox(data);
else if (typeof(T) == typeof(MyCheckedListBox))
innerControl = new MyCheckedListBox(data);
else
throw new ArgumentException("Some descriptive error message");
innerControl.Dock = DockStyles.Fill;
this.Controls.Add(innerControl);
}
}
...
GenericListBox<MyListBox> ctl = new GenericListBox<MyListBox>(someData);
Of course, you'd have to provide wrapper methods for many functions, or just expose the innerControl object as a ListControl and wrap any methods from below that on the inheritance chain.
Honestly though, I don't think this is the best way to do it. I'd suggest making a factory for it, and just passing an enum with the type of control to create:
public static ListControl CreateListControl(MyControlTypes ctlType, DataObject data)
{
if (ctlType == MyControlTypes.NormalListBox)
return new MyListBox(data);
else
return new MyCheckedListBox(data);
}
(MyControlTypes would be an enum, of course)
Of course, I might be misunderstanding you completely, but maybe this will spark an idea.
|
|
|
|
|
Your first suggestion is nearer to what I want. I was hoping not to use encapsulation, but this is a good start for the generic knowledge I'm lacking. Thanks for taking the time.
Regards
Angel
*********************************************
|
|
|
|
|
Hi,
Hello friends, i need your help..my problem is that i want to export my sql server database to MS access file in a specified location say in a folder..i am using .net 2.0 c# as the language...can anybody help me...
Regards
Alex.
|
|
|
|
|
It's hard to say how to help, when you give no indication of what you have done so far, and where you are stuck.
So... What have you done so far? Where are you stuck?
|
|
|
|
|
Hi,
I have a problem with the conversion of a string of type "07:30" into a time. I want to take only the time, without the date. I tried
DateTime openTime = DateTime.Now.ToShortTimeString(open);
,where open = "07:30".
Please help me with this problem.
|
|
|
|
|
Hi,
a DateTime always contains date and time.
TimeOfDay gives time since midnight.
Hence:
DateTime dt=DateTime.Parse(myInputString);
TimeSpan time=dt.TimeOfDay;
|
|
|
|
|
But if my string is like this "07:30", what can I do? Because I tried that method and my result is 00:00:00.

|
|
|
|
|
When I run the code snippet
DateTime dt=DateTime.Parse("07:30");
TimeSpan time=dt.TimeOfDay;
log(time.ToString());
I get "07:30:00" as expected.
BTW if you're not satisfied by Parse, there also is DateTime.ParseExact().
|
|
|
|
|
Cool. I've always padded it out with current day/month/year. Learn something new everyday here....
Regards
Angel
*********************************************
|
|
|
|
|
try
<br />
System.DateTime nowTime = System.DateTime.Now;<br />
<br />
System.DateTime openTime = System.DateTime.Parse(nowTime .ToShortDateString() + " 07:30:00");<br />
<br />
TimeSpan open = nowTime - openTime;<br />
<br />
<br />
if (nowTime > openTime)
Console.WriteLine("We've been open for {0:0} minutes", open.TotalMinutes);<br />
else<br />
Console.WriteLine("We will open in {0:0} minutes", -open.TotalMinutes);<br />
<br />
There must be better methods though...?
Regards
Angel
*********************************************
|
|
|
|
|
The problem is that I will take the string from a Xml file and I cant use it like that. I really need help.
|
|
|
|
|
what exactly are you trying to do? can you post more code?
Regards
Angel
*********************************************
|
|
|
|
|
I read a Xml file and from it I will have a string, for example the string name is open="07:30".
I tried to read it like this
DateTime oTime = DateTime.Parse(open);
TimeSpan openTime = oTime.TimeOfDay;
where openTime is of type TimeSpan.
But the result is 00:00:00 and it doesnt work.
|
|
|
|
|
You still haven't posted any code....
I hope this isn't homework I am helping with......
So you have xml file eg:-
<br />
<myxml><br />
<times open="07:30" close="09:30" /><br />
</myxml><br />
And you want to know how long until it opens. Timespan is the difference between two times. If you want to know how long it is until the shop opens, then you need two things. The current time, and the time it opens.
I am assuming you now have "07:30" stored in a string. I am also assuming that you want to know this information about 'today', and not any day in the future.
C# DateTime class, as has already been mentioned, must have both a date and time portion.
To get the current time :-
System.DateTime currentTime = System.DateTime.Now;
As I am writing this, this will give you:
02/05/2007 15:26:34
OK. That is the time now. You now want to know the time (today) when your shop/office etc opens.
So, take the current datetime (currentTime) and replace the time portion with your time.
System.DateTime openTime = System.DateTime.Parse(currentTime.ToShortDateString() + open + ":00" );
The extra ":00" is because a valid time (I think) needs hours:minutes:seconds and yours ("07:00") doesn't have this.
So you now have currentTime and openTime.
If you get the timespan of these, and use the TotalMinutes member, you get the number of minutes until the shop opens, or the number of minutes it has been open if this number is negative.
TimeSpan open = nowTime - openTime;<br />
int MinutesUntilWeOpen = open.TotalMinutes;
Is this homework or a real requirement? Post what you have tried up until now - it makes understanding your requirement a lot easier.
Regards
Angel
*********************************************
|
|
|
|
|
Thanks for trying to help me, but I dont want to make that. I want only to show the hour I read it from the Xml file. That's the problem, because I tried it and it shows something like 00:00, and not 07:30, like it should.
|
|
|
|
|
OK - lets try again. Show me the whole function that you have at the moment. Show me your input, and what you expect as output.
Regards
Angel
*********************************************
|
|
|
|
|
this is the function which reads the Xml File and is part of a class Cities.
public class Cities : List<city>
{
public void OpenCityList(string filename)
{
DataSet cityDS = new DataSet();
try
{
this.Clear();
cityDS.ReadXml(filename);
DataRowCollection cities = cityDS.Tables[0].Rows;
foreach (DataRow city in cities)
{
this.Add(new City(Convert.ToInt32(city["X"], CultureInfo.CurrentCulture), Convert.ToInt32(city["Y"], CultureInfo.CurrentCulture), Convert.ToInt32(city["Demand"], CultureInfo.CurrentCulture), Convert.ToString(city["Open"], CultureInfo.CurrentCulture)));
}
}
finally
{
cityDS.Dispose();
}
}
private TimeSpan startHour;
public TimeSpan StartHour
{
set
{
startHour = value;
}
get
{
return startHour;
}
}
public void ShowCityHour()
{
foreach (City cityhour in this)
{
startHour = cityhour.OpenTime;
}
}
}
And in another class, named City I have :
public class City
{
private int demand;
private TimeSpan openTime;
public City(int x, int y, int citydemand, string open)// I am interested about the string open
{
Location = new Point(x, y);
demand = citydemand;
DateTime oTime = DateTime.Parse(open);
TimeSpan openTime = oTime.TimeOfDay;
}
public TimeSpan OpenTime
{
get
{
return openTime;
}
set
{
openTime = value;
}
}
}
It is something like that. I take the data from the Xml file and I store it in the string open, and I want to convert it to time, because after that I will have to sort the whole list in order of the hours.
|
|
|
|