|
I have a dataTable with an integer column called RAM_amt for amount of RAM on a machine. The DataTable is populated by a business logic object that I cannot change.
The RAM_amt is in bytes but I want the text box to display it in megabytes if the value let say is less than 1000 megabytes and display in gigabytes if the value is 1 gigabyte or more.
The logic is pretty easy but where would I put this code? Where is the msot efficient place to put this?
|
|
|
|
|
This is just an idea but perhaps you could programmatically add another column to the DataTable to use for the friendly display of the amount of RAM. After adding the new column perform a loop for each row in the DataTable and update the new column based on your "RAM_amt" column. Then bind that new column to your TextBox through code.
You would place this code somewhere after getting the DataTable. You can then remove any existing bindings for the TextBox and add the new one. Assuming you had a DataTable called dt it might look something like the code below.
dt.Columns.Add("RAM_text", Type.GetType("System.String"))<br />
Dim dr As DataRow<br />
For Each dr In dt.Rows<br />
dr("RAM_text") = GetFriendlySize(dr("RAM_amt"))<br />
Next<br />
TextBox1.DataBindings.Clear()<br />
TextBox1.DataBindings.Add(New Binding("Text", dt, "RAM_text"))
GetFriendlySize() would be a Function that calculates the display text from the byte value.
|
|
|
|
|
Does anyone think that using complex data binding to synchronize a listbox to textboxes is bad? I am binding a listbox to the same dataTable that 5 other textboxes are bound to so that the listbox works as a navigator.
For what I'm doing this seems like a quicker but also more efficient and error free solution.
Here are my other options
1. Manually through loops populate the listbox from the datatable. Then add a Listbox.selectedIndexChange handler to do a dataTable.rows.find for the selected item on the listbox. Then refresh the appropriate text boxes.
2. Bind only the listbox to the datatable. Then add a Listbox.selectedIndexChange handler to do a dataTable.rows.find for the selected item on the listbox. Then refresh the appropriate text boxes.
I've read some articles saying that complex databinding is bad programming practice.
Is there a performance gain by complex binding versus manual code?
|
|
|
|
|
hi all,
how do i know whether capslock is on?
i do not mean whether is is pressed, something like this this doesnt work
class form1 'keypreview is true
inherits form
'windows forms designer generated code etc
private CapsOn as boolean = false
protected overrides sub onkeydown(e as keyeventargs)
mybase.onkeydown(e)
if e.keycode = keys.capslock then capson = not capson
end sub
end class
beacuse when capslock is on before app starts stuff goes the wrong way around...
does anyone have a idea?
a api or something?
thanks, mouzik
|
|
|
|
|
.Net framework didn't encapsulate all the Windows APIs yet so you will have to call the following windows api:
Private Declare Function GetKeyState Lib "user32" (ByVal virtKey As Integer) As Short
Then call it.
For example:
if GetKeyState(Keys.CapsLock) = 1 then capson = true
|
|
|
|
|
thanks rudy!
although it didnt work at first, i got it working in the end:
Private Declare Function GetKeyState Lib "user32" (ByVal virtKey As Integer) As Integer
and to call it:
CapsOn = CBool((GetKeyState(Keys.CapsLock) And 65535) - 65408))
thanks again!
|
|
|
|
|
Hi i have converted a visual basic 6 project into vb.net.The project has a splash form then login form and then a main form. but what happens after i run the project the splash form appears and on its keypress event the login form is to get loaded but it closes the project . i donot know why. if i make login form the default startup object then also after its a right login it does not dispaly the main form and the project closes. pls help. me and if i use show dialog method then the formLoad events of the forms are not called and no defualt values are set which i try to set them on form load event. Pls tell me something
Thanks
|
|
|
|
|
Normally .net form apps are started by something like this:
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
If you have this and Form1 is your splash screen then the application will exit because it only runs as long as Form1 is open.
So inside the Run statement your application main form should be inserted. All other forms could be shown before this statement. Whats best in your situation depends on your special requirements.
|
|
|
|
|
Does anyone know any techiniques, tricks or anything cool about customizing command buttons and the way they look such as changing their shape, texture etc...???
|
|
|
|
|
Searching CodeProject will give you several hits.
I personally think this and this are fancy.
|
|
|
|
|
hi all,
how do i get the size of a file?
i have looked in the io.file class , but couldnt find a GetFileSize function or something
does anyone have an idea
thanks, mouzik
|
|
|
|
|
Try new System.IO.FileInfo(fileName).Length
|
|
|
|
|
|
Hi Guys..
i'm using the following code (in vb 6 ) to encode an ARABIC String into the UCS2 ,assighned to the StrData Byte Variable then pass the StrData To The Function to do then encoding..
the problem is when i wanted to apply this code in vb.net there were a problem in assighning a string value into the StrData Byte Variable,which tells that can't convert string variable into 1-dimention array of byte.!!
and when i changed the function to accept an array of characters insted of a byte var. it always return the same encoding for any arabic string..!!
do any 1 know how to solve this problem? or know any good simple way to encode arabic string to UCS2 ..?
here is the function in vb6...
Public Function ArabicHex(b() As Byte) As String<br />
Dim s As String, h As String<br />
Dim i As Integer<br />
i = 0<br />
s = ""<br />
While i <= UBound(b)<br />
h = Right("00" & Hex(b(i)), 2)<br />
i = i + 1<br />
h = Right("00" & Hex(b(i)), 2) & h<br />
If h = "000D" Then h = ""<br />
s = s & h<br />
i = i + 1<br />
Wend<br />
ArabicHex = s<br />
End Function
any quick response will be helpfull and thankfull..
confused:
|
|
|
|
|
Hi There!!
When I run the program that I have created for a Pocket PC device it does not show my application on the Project PC Emulator, is it possible to view your created program on there without having to upload it to a real Pocket PC!!, If so please can you give me advice on how to do this.
Thanks
|
|
|
|
|
You need to deploy your app to a Emulator you selected
ASP.NET C# VB VC & SQL Windows APP ...
|
|
|
|
|
Hello there
I have built a mulit-lingual application. The default language is English. When User Change the language I fetch the record from resource file and re-set the labels with the new language. but when I assign the new language, The font which was Bold becomes normal. and from now onwards if you go back to English language it will remain normal.
Any Idea's.... ?
|
|
|
|
|
I am trying to get a listbox to allow drag and drop between another listbox and also act as a navigator for some textboxes bound to columns on a DataTable. I am able to get both to work but not at the same time. Both features require the use of the the MouseDown event handler. However a MouseDown event is just that. Logically you want the MouseDown handler fired by the ListBox Navigation to always run first.
For the drag and drop, I bound the navigation ListBox and the other listbox to their own DataTables that have the same schema. Then I just add and remove DataRows between the 2 datatables for the drag and drop.
For the navigation ListBox, I make sure that the textboxes are bound to the same DataTable the nav-Listbox is bound to. VB.Net and I think the currency manager does the rest. When you click on the nav-ListBox item it brings up the record that the listbox item is tied to and all the textboxes are refreshed.
Here is how I got the ListBox Navigator to work
dtUsedSoftware = getDataTable()<br />
With lstUsedSoftware<br />
.DataSource = dtUsedSoftware<br />
.ValueMember = "SoftwareID"<br />
.DisplayMember = "SoftwareName"<br />
.SetSelected(0, False)<br />
<br />
End With<br />
<br />
txtInstanceName.DataBindings.Clear()<br />
txtInstanceName.DataBindings.Add(New Binding("text", dtUsedSoftware, "InstanceName"))<br />
txtInstalledVersion.DataBindings.Clear()<br />
txtInstalledVersion.DataBindings.Add(New Binding("text", dtUsedSoftware, "InstalledVersion"))
Public Sub lstUsedSoftware_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstUsedSoftware.MouseDown<br />
<br />
If ((e.Button And MouseButtons.Left).Equals(MouseButtons.Left)) Then<br />
'' check to see if lstbox has any items<br />
Dim dtRow As DataRow<br />
dtRow = dtUsedSoftware.Rows.Find(lstUsedSoftware.SelectedValue)<br />
<br />
'commenting the line below makes the listbox navigation work<br />
<br />
lstUsedSoftware.DoDragDrop(dtRow, DragDropEffects.Move)<br />
<br />
'what I really want is for the listbox navigation MouseDown event to fire on MouseUp instead. <br />
End If<br />
End Sub
|
|
|
|
|
Basically you have to force the item selection before calling DoDragDrop. Since the MouseEventArgs gives you the coordinates of the mouse click then you can find out which item got clicked and force the selection as follows:
Dim selectedIndex As Integer = Me.ListBox1.IndexFromPoint(New Point(e.X, e.Y))<br />
lstUsedSoftware.SetSelected(selectedIndex,True)<br />
:<br />
:<br />
lstUsedSoftware.DoDragDrop...<br />
|
|
|
|
|
It worked......and I was going to catch the event with iMessageFilter. That would have been a mess. thanx
Does anyone think that using complex data binding to synchronize a listbox to some textboxes is bad? I've read some articles saying that complex databinding is bad programming practice.
|
|
|
|
|
|
hi
i want to connect a property grid to a button and only show BackColor in this property grid but not with caption "BackColor" and instead of this i want to show for example "ColorButton"
when user changed this property like changing backcolor , color of button must be change.
i can declare my own property but i can't connect that to my button???
how can i do this ????
Best Regards
-------------
MkhProgrammer
|
|
|
|
|
hi all,
i want to pass the text of a textbox in one webform to the text property of a label in another webfor, in the same web application. can anyone tell me. ow it can be done.
thanks in advance.
|
|
|
|
|
The easiest way is to store the required value in Session State.
WebForm1
Session("MyValue") = FromTextBox.Text
WebForm2
If Not Session("MyValue") Is Nothing Then<br />
ToLabel.Text = Session("MyValue")<br />
End If
You could also get the ViewState information from the original WebForm by using the Server.Transfer method. This method requires that the EnableViewStateMac attribute of the WebForm be set to False so that the ViewState is not hashed.
WebForm1
Server.Transfer("WebForm2.aspx", True)
WebForm2
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim fromForm As System.Collections.Specialized.NameValueCollection<br />
fromForm = Request.Form<br />
ToLabel.Text = fromForm.Item("FromTextBox")<br />
End Sub
|
|
|
|
|
I'm trying to change the font of a selected row (not all) in DataGrid. But it's still not yet. Please give your advise with this problem if possible. Thanks a lot.
Phuc Hua
|
|
|
|