|
Why not create separate DataRow arrays for each expression if you want to segregate them, or use OR in your select string if you want to group them all together?
For example (using expresion segregation):
DataTable dt = ...(your data table definition)
DataRow[] drMobile = dt.Select("ItemName = 'mobile'");
DataRow[] drTV = dt.Select("ItemName = 'tv'");
DataRow[] drRadio = dt.Select("ItemName = 'radio'");
DataRow[] drComputer = dt.Select("ItemName = 'computer'");
or (grouping them all together):
DataTable dt = ...(your data table definition)
DataRow[] drows = dt.Select("ItemName = 'mobile' OR ItemName = 'tv' OR ItemName = 'radio' OR ItemName = 'computer'");
By the way, I don't recommend using ArrayList... instead, use Generics, for example, instead of using:
ArrayList al = new ArrayList();
string v1 = "some text";
string v2 = "some more text";
string v3 = "even more text";
// you get the point...
al.Add(v1);
al.Add(v2);
al.Add(v3);
// etc.
and then casting the content back to a string variable:
string v1Str = (string)al[0];
...
Use Generics:
List<string> al = new List<string>();
string v1 = "some text";
string v2 = "some more text";
string v3 = "even more text";
al.Add(v1);
al.Add(v2);
al.Add(v3);
// etc.
now, you don't have to cast the values back to a string when you retrieve them:
string v1Str = al[0];
string v2Str = al[1];
...
Depending on what you are storing in the ArrayList, the cast operation can be very costly in terms of performance.
Microsoft doesn't recommend using the ArrayList in .NET 2.0 and higher.
-- modified at 22:03 Sunday 18th November, 2007
|
|
|
|
|
Thank you very much for your suggestion. Actually I have a data table with 10thousand records and now I have 4-5 items and I want to found any of item is missing or not ..? for that I have to traverse through data table, So I use array list which is having contains method which make traversing fast.
Please give a good solution to resolve this issue.
Also thanks for the guidance of using list instead of array list.
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
Hello, I've recently found stranged things could happen when I set up an event handler for the HandleCreated Event in C# windows controls.
So what is HandleCreated Event? When will it be raised? Thanks in advance.
|
|
|
|
|
Well, a handle is pretty much just a pointer to the object, and can be used for a variety of things. For example say you create a bitmap and draw a picture onto it, and you then wanted to pass this image to another form, instead of passing the whole image, you could just pass the handle and then use Bitmap.FromHandle().
But, i would have thought that the handle would be created at the same time as the instance of an object, unless you can somehow make more. I'm not so savvy with handles. If you check the MSDN documentation you should find the answers you seek.
EDIT: Nevermind, MSDN doesn't help much. It just says that it fires when a handle is created (wow, really?!) and that it is useful for debugging.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
Thanks for your helpful explanation.
|
|
|
|
|
Hello All,
I know there are many on this topic, but after looking at all the articles, i felt lost
and hence posting it here for quick help.
I have a datagridview with columns Task and Status. When the grid is displayed I want the user to select the Status from the combo box in the cell. How do i do this?
My data for the grid is filled up from an Xml.
Please help!
Thanks
D
|
|
|
|
|
Hi,
protected void dgList_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddl = (DropDownList)e.Item.FindControl("ddlStatus");
ddl.SelectedValue = e.Item.Cells[2].Text;
}
}
I hope this helps
"Good Thing Goes With Good People..."
|
|
|
|
|
|
The best RegEx book is the Mastering Regular Expressions book from O'Reilly. You should also download Expresso, a cool app for playing with regex.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Can someone please direct me to some snippet of code that will do the following:
We want to allow our users to upload audio files - we'd like to not limit the format to a specific type (mp3, aud, wav, etc.) but accept all 'reasonable' audio files ... is there a 'generic' routine that can validate that the file being uploaded is indeed an audio file? We can check to see if the extension is acceptable, but that wouldn't prevent a prankster from changing the extension of a non-audio file ... also, what would be the most efficient storage format of audio and can the routine convert it to that format (this would help us control the size of the file uploaded to be within reasonable limits)? Do we have to check for specific file headers or is there a function similar to System.Drawing.Bitmap?
Your assistance is greatly appreciated.
Thx,
TheGAPnoid
|
|
|
|
|
Try reading the first few bytes of the file, and see if it matches up with the extension of the file.
MP3's for example, will probably start with their ID3 tag, so the first three bytes would be:
I D 3
49 44 43
WMA start with their tag, which seems to start with:
0 & ²
30 26 B2
So, you could gather a small database of the headers of the filetypes. And compare the first few bytes of the uploaded file, to the set of bytes you already have.
If you get a file with extension: mp3 and it starts with something other than 49 44 43, you can just say that the extension does not match the filetype. Though you'd have to investigate this further. Im not sure what an mp3 starts with if it has no tag (can you get an mp3 without an ID3 tag?)
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
Well ...an hour passed and I already have another question.
I have the data from a database in a data grid, except the id.
I want to know how can i take the id into a variable if a know the other fields of the row.
To understand exactly:
first column is the name, second column is the job;
I have the name and the job and i wanna find the ID and put it in a variable.
|
|
|
|
|
why don't you load the ID at the same time you are loading other fields and keep it either in datakeynames or in a hidden column of the datagrid
-----
|
|
|
|
|
Hi,
I try to pass two strings from a form to another.
in the first form the strings are stored in a data grid.
I've already retrieved the values fro the grid and i have 2 strings value1 and value 2.
how can i pass them from form 1 to form 2 and store them in two different text boxes in form 2?
Thanks!
|
|
|
|
|
Steauaclau,
There are several ways to do it...
1. Create public static string firstString and reference it by the class name.
public class Form1 : Form
{
public static string firstString
....
}
public class Form2 : Form
{
Form2_OnLoad()
{
tbxStringValue.Text = Form1.firstString;
}
....
}
2. If one form calls the other, it could use a constructor to pass the value in.
Hope this helps.
Hogan
|
|
|
|
|
snorkie wrote: public class Form1 : Form
{
public static string firstString
....
}
Why is the field public. This is not a valid time to make a field on a class public. It breaks the rules of encapsulation (one of the tenets of Object Orientation)
For more information about why making fields public is a bad idea please read:
* Why make fields in a class private, why not make them public?[^]
*The public fields debate again[^]
Also, you make it static. Why? What purpose does that serve? You have some data in controls which reside in instance fields and then you want to transfer it to a static field! Why?
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|
|
I agree with you that it isn't the best approach, and I will read the articles, but I wanted to give a quick and dirty answer to the issue at hand. Probably a bad idea to suggest quick and dirty...
Thanks for the info!
Hogan
|
|
|
|
|
|
Thanks a lot!! I've maid it )
|
|
|
|
|
You are welcome
|
|
|
|
|
My problem started off with a simple directory copy. I needed to copy the directory to another location. After creating the directory, I used the following code to set up permissions correctly. That worked great! It seemed too easy...
DirectoryInfo dirSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo dirDest = new DirectoryInfo(destinationDirectory);
dirDest.SetAccessControl(dirSource.GetAccessControl());
Now I find out that my destination is a named pipe. This breaks the .NET framework implementation. So I started down the path of using the API. I found the Kernel32 CreateDirectory command to create a directory over named pipes. The documentation there isn't great. (I would like to update it with more information when I'm done.)
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool CreateDirectory(string lpPathName, IntPtr lpSecurityAttributes);
I can't seem to find a way to get an IntPtr to the security attributes of the current directory from the .NET framework. Is there a simple way to do this that I'm missing? The .GetAccessControl() method of a DirectoryInfo object doesn't return anything like an IntPtr.
Any ideas/help/suggestions on how to use the API call to create the directory and apply the source directory's Acccess Control items would be awesome.
Thanks!
Hogan
|
|
|
|
|
<iframe id="simpleEditor" runat="server"> </iframe> <br />
<br />
On Page_Load event how can i set the default value of iframe. Do i need to call a javascript function to the set the value if so how can i call a javascript from the .cs file or code behind file.<br />
<br />
Thanks
|
|
|
|
|
look the answer in asp.net forum
-----
|
|
|
|
|
Hi All,
I have a group of radio buttons, and I am trying to determine which is checked. I access the Group Box container, but I can't find the collection for accessing the radio buttons. I want to do something similar to:
RadioButton b = (RadioButton)groupBox.Selected();
string s = b.Text; As always, any help would be appreciated.
Thanks,
Jeff
The following does not compile with the error, "error CS1579: foreach statement cannot operate on variables of type 'System.Windows.Forms.GroupBox' because 'System.Windows.Forms.GroupBox' does not contain a public definition for 'GetEnumerator'":
foreach (RadioButton b in grpDestination)
{
if (b.Checked)
{
...
}
}
|
|
|
|
|
Try something like this:
foreach (Control control in grpDestination.Controls)
{
RadioButton radio = control as RadioButton;
if (radio != null && radio.Checked)
{
...
}
}
|
|
|
|