|
e.Handled = char.IsDigit(e.KeyChar )
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
thanks a lot..
i have one more doubt.
i need a textbox where the user can enter only
Alphabets (A-Z and a-z)
Space
and also allow them to use backspace and delete keys.
this is the code i tried
if (!((e.KeyChar >= 'A' && (e.KeyChar <= 'Z') || ((e.KeyChar >= 'a') && (e.KeyChar <= 'z')))))
{
e.Handled = true;
}
if (char.IsSeparator(e.KeyChar))
{
e.Handled = false;
}
but the above code wont allows the user to use backspace
plz help me to set e.handled = false when the key pressed by the user is a backspace so that he can erase the last character entered
|
|
|
|
|
This worked for me
int keycode = e.KeyChar;
if (!((e.KeyChar >= 'A' && e.KeyChar <= 'Z') || (e.KeyChar >= 'a' && e.KeyChar <= 'z') || keycode == 8 || keycode == 32)) {
e.Handled = true;
}
|
|
|
|
|
hey Navaneeth...
thanks a lot..
i solved my problem like this
if (!((e.KeyChar >= 'A' && (e.KeyChar <= 'Z') || ((e.KeyChar >= 'a') && (e.KeyChar <= 'z')))))
{
e.Handled = true;
}
if ((char.IsWhiteSpace(e.KeyChar)) || (e.KeyChar == (char)ConsoleKey.Backspace))
{
e.Handled = false;
}
but your solution is the smarter way to handle it..
I am new to codeproject.com and people like you will make this a better place for people like me to find solutions to their problems!!!
cheers!!
Arun
|
|
|
|
|
Hi,
two comments:
1. it is KeyEventArgs (as given by KeyDown and KeyUp) that holds a SuppressKeyPress property
2. all .NET classes are identical in C# and VB.NET, they are language-agnostic.
|
|
|
|
|
I am doing this in VC# and the object of KeyEventArgs didnt show the SuppressKeyPress.
instead the keyhit can be handled by
kKeyEventArgs e
e.Handled = true;
thnanks to Greeg !!
|
|
|
|
|
I have a user control that has 2 nested datalists. The second datalist requieres arguments from the first one to display the data. The main one shows the Product Categories and the second one shows the products for the selected category. When the user selects an item from the first I am calling "DataList_ItemCommand" which sets a session variable and then programatically binds the data for the second datalist. SOMETIMES (Mostly when the results are big or if I click to fast) I get an error on Internet Explorer which forces me to refresh the screen to see the data... Any ideas on what could be happening? Solutions?? Thanks Guys!
public void DataList_ItemCommand(Object sender, DataListCommandEventArgs e)
{
decimal nCpPk = (decimal)CategoryList.DataKeys[e.Item.ItemIndex];
Session["CategoryId"] = nCpPk;
BindData();
}
public void BindData()
{
//Dataset
DataSet DS = new DataSet();
//Create a connection to the SQL Server.
string strConnectionString = ConfigurationManager.ConnectionStrings["EckeMasterConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(strConnectionString);
//Session Variables
decimal tmpCategoryId = (decimal)Session["CategoryId"];
decimal tmpMainCateg = (decimal)Session["MainCateg"];
string tmpShipWeek = (string)Session["ShipWeek"];
int tmpAvailableOnly = (int)Session["AvailableOnly"];
string tmpProdForm = (string)Session["ProdForm"];
//Create a DataAdapter, and then provide the name of the stored procedure.
SqlDataAdapter MyDataAdapter1 = new SqlDataAdapter("EWO_ProductsByCategory", conn);
MyDataAdapter1.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter ParCateg = new SqlParameter("@CategoryId", SqlDbType.Int);
ParCateg.Value = tmpCategoryId;
MyDataAdapter1.SelectCommand.Parameters.Add(ParCateg);
SqlParameter ParMainCateg = new SqlParameter("@MainCateg", SqlDbType.Int);
ParMainCateg.Value = tmpMainCateg;
MyDataAdapter1.SelectCommand.Parameters.Add(ParMainCateg);
SqlParameter ParProdForm = new SqlParameter("@ProdForm", SqlDbType.Int);
ParProdForm.Value = tmpProdForm;
MyDataAdapter1.SelectCommand.Parameters.Add(ParProdForm);
MyDataAdapter1.SelectCommand.CommandTimeout = int.MaxValue;
MyDataAdapter1.Fill(DS, "Products");
//'Create a DataAdapter, and then provide the name of the stored procedure.
SqlDataAdapter MyDataAdapter2 = new SqlDataAdapter("EWO_ProductDetail", conn);
MyDataAdapter2.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter ParCategA = new SqlParameter("@CategoryId", SqlDbType.Int);
ParCategA.Value = tmpCategoryId;
MyDataAdapter2.SelectCommand.Parameters.Add(ParCategA);
SqlParameter ParMainCategA = new SqlParameter("@MainCateg", SqlDbType.Int);
ParMainCategA.Value = tmpMainCateg;
MyDataAdapter2.SelectCommand.Parameters.Add(ParMainCategA);
SqlParameter ParShipWeekA = new SqlParameter("@ShipWeek", SqlDbType.DateTime);
ParShipWeekA.Value = tmpShipWeek;
MyDataAdapter2.SelectCommand.Parameters.Add(ParShipWeekA);
SqlParameter ParAvailOnlyA = new SqlParameter("@AvailableOnly", SqlDbType.Int);
ParAvailOnlyA.Value = tmpAvailableOnly;
MyDataAdapter2.SelectCommand.Parameters.Add(ParAvailOnlyA);
SqlParameter ParProdFormA = new SqlParameter("@ProdForm", SqlDbType.Int);
ParProdFormA.Value = tmpProdForm;
MyDataAdapter2.SelectCommand.Parameters.Add(ParProdFormA);
MyDataAdapter2.SelectCommand.CommandTimeout = int.MaxValue;
MyDataAdapter2.Fill(DS, "ProdForms");
DS.Relations.Add("MyRelation", DS.Tables["Products"].Columns["StockSiPk"], DS.Tables["ProdForms"].Columns["StockSiPk"]);
Products.DataSource = DS.Tables["Products"].DefaultView;
Products.DataBind();
for (int i = 200; i > 0; i--)
{
//Nothing here just waiting toprevent timeouts -- not sure if this is really working
}
}
|
|
|
|
|
tip:
use PRE tags when posting code blocks, then someone might make an effort to actually read it...
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi there.
I want to convert "Black" string to Brush.
For example something like this :
this.comboBoxColor.Background = (Brush)"Black";
How can we do it?
Can you help me ?
Freshman
|
|
|
|
|
This may work depending on the input string:
string colorName = "Black";
SolidBrush brush = new SolidBrush(Color.FromName(colorName));
You can find a list of available colors here[^].
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks Greeeg.
This code doesn't work in WPF.
I'm using WPF !
Freshman
|
|
|
|
|
Well, he's given you the only possible answer. That's how you get a color from a string, you need to build whatever brush type you need from there.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
|
I may have misread your question?
In code:
ComboBox comboBox1 = new ComboBox();
Brush backgroundBrush = Brushes.Black;
this.comboBox1.Background = backgroundBrush;
In Xaml:
comboBox1 background="Black"
|
|
|
|
|
I would like our project DLL’s placed into a sub-folder(\plugins). But when I try to run the application, it can’t find them.
In the reference paths, I added a relative search path (.\plugins) and tried a micro path ($(TargetPath\plugins)). Neither seems to work. Unless the dll is in the same directory, I get an exception. The exceptions are the same. Can’t find file.
Thanks
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
By default, your application looks for its assemblies in one directory, so the exe and the dlls should be in the same directory. If you want to do something different then you have to take over the whole lifecycle of the assembly. In other words, you need to look at Assembly.Load .
|
|
|
|
|
After research I also found that you can give the X.exe an X.exe.config file that defines other sub-folders to search.
This works for me.
Thanks
Glenn
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
hi friends,
i have 16 images in my form, but what i want is to access them by an index or something that makes it easy to call them. i don't want to call them their name (which is clearly diffrent from an other) each time. i want to make an array of them. how can i do that?
generally, how can i achive the controls (such as buttons, textboxes, etc) in my form?
is there any 'foreach'-like way?
thanks
modified on Tuesday, July 1, 2008 3:45 PM
|
|
|
|
|
Well, you could use one of the many array or list type structures that .NET supports. You could always implement this by creating a generic List of your images, which can be iterated over with a minimum of fuss. For example:
List<Image> images = GetImagesFromDb();
foreach (Image img in images)
{
}
|
|
|
|
|
I have to fill the list each time the programs starts, but for this, i have to get the name of each picture and write a line of code for adding each to list.
Imagine i have dragged some PictureBox from toolbox in design form. now i want them without calling their name. i want them in in an array. how is it? or something like this:
foreach(Object obj in ...)
if (obj is Image) MessageBox.Show("this is an image");
what should i write in blank?
thanks for your answer
|
|
|
|
|
Do you mean something like this?
foreach (Control c in this.Controls)
{
PictureBox pic = c as PictureBox;
if (pic != null)
...
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
yes, thank you. that can be what i was looking for
|
|
|
|
|
|
thank you but isn't the ImageSize of pictures limited (256 * 256)? what is the solution? how can i have something like ImageList but with much bigger size of image?
thanks again
|
|
|
|
|
Do you need to display the images or just keep track of them inside a list?
If you need to display them, then you could add PictureBox controls dynamically to the form at runtime, something like
PictureBox pic = new PictureBox();
pic.Image = ...;
Controls.Add(pic);
If you just need a list then this will do the trick:
List<Image> images = new List<Image>();
images.Add(...);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|