|
Hello,
You could handle the "KeyPress" event of your textbox instance, or better inherit your own textbox and override the protected OnKeyPress method.
Then you could do:
protected override void OnKeyPress(KeyPressEventArgs e)
{
string _allowedkeychars = "1234567890";
if (_allowedkeychars.IndexOf(e.KeyChar) < 0)
{
e.Handled = true;
return;
}
base.OnKeyPress (e);
}
private void YourTextBoxKeyPress(object sender, KeyPressEventArgs e)
{
string _allowedkeychars = "1234567890";
if (_allowedkeychars.IndexOf(e.KeyChar) < 0)
{
e.Handled = true;
return;
}
}
All the best,
Martin
|
|
|
|
|
yea that looks alot helpful to me. thanks alot Martin I appreciate this!
|
|
|
|
|
Hi, Actually I want to draw many rectangles on the screen and want to show all of them at once. Is there any function like BeginUpdate and EndUpdate in c#. so that the drawing process is not shown to the viewer.
|
|
|
|
|
No there isn't really, what you want is double-buffering, if you're using .NET 2 then there should be a DoubleBuffered property on the control you're inheriting from. If not then use base.SetStyle in the constructor of the class.
The BeginUpdate and EndUpdate are used in a different way, say you have a ListBox , if you want to add 1000 items to it normally each time you add an item the Invalidate method is called, this will cause the control to recalculate it's entire contents and redraw all of them. If you use the Begin/EndUpdate pair then what this does is set a flag to say that when an item is added / deleted changed it's not meant to be redrawn. When you call the EndUpdate function when all the items have been added then it calls the Invalidate method to redraw the control (and clears the flag).
You can see the obvious benefits, in the first method (no Begin/EndUpdate ) the control is redrawn 1000 times as each item is added (thus producing a flicker (unless you have an awesomely specced machine)), in the second it only redraws once when everything has finished.
|
|
|
|
|
Hi, thanks for reply, actually I am drawing almost 10000 rectangles on the screen. My main function of drawing is called in the form PAINT function. I have enabled the double buffered property but it is not working. Can you give me a bit more detail? Thanks for help.
|
|
|
|
|
My only suggestion would be to move any position calculations to outside the Paint function because that is called more often. I.e. do as few mathematical calculations for the positioning / size of the elements in the Paint event, do that inside the Resize .
|
|
|
|
|
Hello,
I m using Visual Studio 2005.Doing windows project in C#.Net.In that
i m using popup window forms.All details in text boxes are getting filled.But combo box and list boxes are not showing correct records?
I m taking records from database (sql server 2000) depending on the id of selected record from the datagrid.I m using Binding navigator.On that i have taken command button.On click event of that button i m displaying another form,in that form i m getting above explained problem.
I have debugged & found that all values are getting retrived correctly.It showing the value of selected index correctly also value in selected text field is also correct.Then why Combobox & ListBox contents are not getting updated.....
hello
|
|
|
|
|
Can you post the relevant pieces of code please, it'd be a great help in trying to help you diagnose this problem.
|
|
|
|
|
hmmmm!!!I m Using BindingNavigator on user control.On that i have taken Button,on click event of that i m displaying another windows form using showdialog...
hello
|
|
|
|
|
Can you post the code which is surrounding the ShowDialog, the bits that set the combo boxes etc.
|
|
|
|
|
private void bindingNavigatorCreateResumeItem_Click(object sender, EventArgs e)
{
int EmployeeId = 0;
DataSet dsEmlpoyee;
dsEmlpoyee=(DataSet)((BindingSource)grdVwEmpOverview.DataSource).DataSource;
if (grdVwEmpOverview.CurrentRow!=null)
{
EmployeeId = BaseObject.GetValue_Int32(grdVwEmpOverview.CurrentRow.Cells["EmployeeId"].Value);
string EmpName = Convert.ToString(grdVwEmpOverview.CurrentRow.Cells["ShortName"].Value);
frmEmployeeResume ofrmEmployeeResume = null;
ofrmEmployeeResume = (frmEmployeeResume)CCommonFunction.ShowChild(frmMain.Me, CConfiguration.ChildForms.EMPLOYEECREATERESUME);
ofrmEmployeeResume.ClearForm();
ofrmEmployeeResume.ShowEmployeeDetails(ref dsEmlpoyee, EmployeeId);
ofrmEmployeeResume.ShowDialog();
}
}
//ShowEmployeeDetails on other form.
public void ShowEmployeeDetails(ref DataSet DsEmployee, int EmployeeId)
{
DataRow[] drRequest = null;
try
{
m_EmpId = 0;
drRequest = DsEmployee.Tables[0].Select("fldEmployeeId=" + EmployeeId);
if (drRequest.Length > 0)
{
m_EmpId = EmployeeId;
txtPersonalno.Text = drRequest[0]["fldEmployeePersonnelNo"].ToString();
txtShortname.Text = drRequest[0]["fldEmployeeShortName"].ToString();
txtFirstname.Text = drRequest[0]["fldEmployeeFirstName"].ToString();
txtSurname.Text = drRequest[0]["fldEmployeeSurname"].ToString();
cmbStatus.SelectedIndex = Convert.ToInt32(drRequest[0]["fldEmployeeStatus"].ToString());
cmbMaritalStatus.SelectedIndex = Convert.ToInt32(drRequest[0]["fldEmployeeMaritalStatus"].ToString());
cmbCitizenship.SelectedValue = Convert.ToInt32(drRequest[0]["fldEmployeeCitizenship"].ToString());
cmbPAddrCountry.SelectedValue = Convert.ToInt32(drRequest[0]["fldEmployeePAddrCountryId"].ToString());
}
}
catch (Exception ex)
{
StaticUtils.LogExceptionAndContinue(ex, "frmEmployeeDetails.ShowRequestDetails()");
}
}
-- modified at 7:04 Wednesday 14th February, 2007
Help Please!!!
|
|
|
|
|
Two questions, are the comboboxes databound in anyway? I'm guessing not.
Do you have the STAThread attribute applied to your Main function? If not it can produce some really really bizarre behaviour.
|
|
|
|
|
Yes i have applied the STAThread attribute to main function.
During debugging it shows the records correctly......Then why combo & list box contents r not showing correct value...
Help Please
|
|
|
|
|
One thing I noticed is for these two lines:
cmbCitizenship.SelectedValue = Convert.ToInt32(drRequest[0]["fldEmployeeCitizenship"].ToString());
cmbPAddrCountry.SelectedValue = Convert.ToInt32(drRequest[0]["fldEmployeePAddrCountryId"].ToString()); It'd be better as .SelectedValue = (int)(drRequest[0]["fieldname"]); Because what your code is doing is converting an integer (stored in object form because of being late-bound) to a string and then back again, where as if you just cast it it'll be faster and happier.
The code looks correct, the only thing I can think of at the moment is how have the combo boxes been populated? Are they bound to the data source?
|
|
|
|
|
Yes,combobox & listbox bound to the datasource....during page load
|
|
|
|
|
I just helped out someone who has a similar problem with data binding, try running the code without the debugger attached (Ctrl+F5), this worked for his solution for some odd reason. Alternatively you could try calling ComboBox.Refresh() to force it to redraw itself.
|
|
|
|
|
|
how i will change windows date time format? It should change the system's date time format too.
-- modified at 5:39 Wednesday 14th February, 2007
|
|
|
|
|
Format Info
DateTime objDate = DateTime.Now;<br />
String strFormatedDate = objDate.ToString("yyyy-mm-dd HH:mm:ss");
Edit:
Wrong topic? OS/SysAdmin
Anyway you can change the windows date time format in Start->Configuration Screen->Languagesettings
There you can change all currency and formats...
-- modified at 5:41 Wednesday 14th February, 2007
|
|
|
|
|
Check the registry key in regedit: HKEY_CURRENT_USER\Control Panel\International
Here are all the windows format settings stored. To edit this value's from within your program you have to use the Microsoft.Win32.Registry class.
PS. When you want to edit/update an value you need to use the method CreateSubKey and not OpenSubKey
This code will change the long date time representation of windows to DayName DayOfWeek MonthName 4-digit Year:
RegistryKey objReg = Registry.CurrentUser.CreateSubKey(@"\Control Panel\International");<br />
objReg.SetValue("sLongDate", "dddd d MMMM yyyy");
Hope this is usefull...
|
|
|
|
|
Hai all,
In my project i want to generate an excel report from datgrid...
i just want to export my contents of datagrid to excel... can anyone
help me with c# sample codings.......
with Regards,
Imthiyas Ahamed.A
|
|
|
|
|
at first you have to select the reference named:microsoft excel 10.0 object lib and microsofr office 10.0 object lib
then u may use this or some thing like this
==>
string Path = @fileName;
// initialize the Excel Application class
Excel.ApplicationClass app = new ApplicationClass();
// create the workbook object by opening the excel file.
Excel.Workbook workBook = app.Workbooks.Open(Path,0,true,5,pass1,pass2, true,
Excel.XlPlatform.xlWindows,"\t",false,false,0,true,1,0);
// get the active worksheet using sheet name or active sheet
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
// This row,column index should be changed as per your need.
// i.e. which cell in the excel you are interesting to read.
int row=2;
while ( ((Excel.Range)workSheet.Cells[row,1]).Value2 != null )
{
for(int a=1;a<=col;a++)
{
if(((Excel.Range)workSheet.Cells[row,a]).Value2 != null )
totSiz[row-2,a]= ((Excel.Range)workSheet.Cells[row,a]).Value2.ToString();
}
row++;
}
|
|
|
|
|
how can i get ipaddress into database?
String strHostName;
//= new String("");
if (args.Length == 0)
{
// Getting Ip address of local machine...
// First get the host name of local machine.
strHostName = Dns.GetHostName();
//MessageBox.Show(strHostName);
}
else
{
strHostName = args[0];
}
// Then using host name, get the IP address list..
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
strip = addr[i].ToString();
//MessageBox.Show(strip);
}
Is it proper?It is stored in 'strip' variable, which i have to call later in a function. can u get it?
How shu i declare these : args,Dns,args[0],IPHostEntry,IPAddress[] ?
thanx
|
|
|
|
|
define variabel in top of page. so it stored permanently while u'r application in running mode.
write this on top of page.(global variabel define)
if think.
public string var1;
|
|
|
|
|