|
I'd do something like this:
public class MyThingy {
private bool testConnectionComplete = false;
private bool testConnectionResult = false;
....
public override void Form_Load(...) {
Thread tcStart = new Thread(new ThreadStart(this.TestConnection));
tcStart.Start();
Thread tcMonitor = new Thread(new ThreadStart(this.CheckTestConnection));
tcMonitor.Start();
}
public void TestConnection() {
this.testConnectionResult = WhateverYourResultIs;
this.testConnectionComplete = true;
}
public void CheckTestConnection() {
while( this.testConnectionComplete == false ) {
}
}
}
Of course, there may be better ways...
Jeremy Kimball
|
|
|
|
|
Do anyone know how to get back from the client the values of a data grid when columns have been added dinamically?
I noticed that if the AutoGenerateColumns flag is set to true and a dataset is binded to the DataGrid, postbacks include all the cells, even when the user changed values. This allows to add editing capabilities by traping the Update and Edit events.
However, if the columns are added dinamically (let's say template columns need to be used), no columns appear on the postback. See code below.
Notice that this part of the code
// BoundColumn pDBColumn = new BoundColumn();
// pDBColumn.DataField = "ARTIST";
// pDBColumn.HeaderText = "ARTIST2";
// DataGrid1.Columns.Add (pDBColumn);
adds a column dinamically. The column gets added to the response, but is missing on the client's request.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TemplateColumns
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label LblDebug;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
DataGridBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGridBind()
{
// BoundColumn pDBColumn = new BoundColumn();
// pDBColumn.DataField = "ARTIST";
// pDBColumn.HeaderText = "ARTIST2";
// DataGrid1.Columns.Add (pDBColumn);
// Simple bind to a TextBox control
if (Session["TheDataset"] == null)
{
DataSet pDS0 = new DataSet("EmployeesDataSet");
pDS0.ReadXml(@"c:\cd_catalog.xml");
Session["TheDataset"] = pDS0;
}
DataSet pDS = Session["TheDataset"] as DataSet;
DataGrid1.DataSource = pDS;
DataGrid1.DataBind();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.SelectedIndex = e.Item.DataSetIndex;
DataGrid1.EditItemIndex = DataGrid1.SelectedIndex;
this.LblDebug.Text = "Cells on DataGrid1_EditCommand: " + e.Item.Cells.Count.ToString();
DataGridBind();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.LblDebug.Text = "Cells on DataGrid1_UpdateCommand: " + e.Item.Cells.Count.ToString();
DataGridBind();
}
}
}
|
|
|
|
|
Can't quite get this right. I have:
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct MIDIHDR <br />
{<br />
[MarshalAs(UnmanagedType.LPStr)]<br />
public String Data;<br />
public uint Length;<br />
public uint RecBytes;<br />
public uint User;<br />
public uint Flags;<br />
public uint Next;<br />
public uint reserve;<br />
public uint Offset;<br />
public uint Reserved;<br />
}<br />
I am having problems getting the right MIDIHDR.data value, I think. I am building the data as follows:
I am building the string with a StringBuilder object.
I StringBuilder.Append() anywhere from 4 to 16 bytes.
I set MIDIHDR.data = StringBuilder.ToString() and
MIDIHDR.Length = StringBuilder.Length
When I test it by sending the MIDIHDR to a midiOutLongMsg call, I have gotten either no sound, or the same, wrong note, no matter what string I send.
example bytes {153, 41, 127, 0}
StringBuilder.ToString() outputs "153411270"
with a length of 9
What i believe this is doing is converting the byte with a value of 153 to a string of length 3 ("153"). Is there a way to build this string as just the 4 bytes? Can I, for example, cast the byte to char before appending to the string? Am I gonna have problems with the unicode/ansi conversion in the string and it's length as its size in the struct??? Or is the marshalling of the struct really taking care of all this and I just have an error elsewhere?
( I may not understand the proper way to use midiOutLongMsg() to send multiple ShortMsg's simultaneously...)
I was making headway with marshalling/interop and have been successful with everything but this. I have used the same byte data to successfully make calls to midiOutShortMsg. The bytes are actually stored in a struct of 4 bytes coerced into a union as an int. So it would be neat if I could just build the string using this int value to represent the 4 bytes, but for now I just wanna get it to work.
i am going to keep playing and researching, but I thought I'd stick the question here to see if I get a nibble.
Any help or insight would be greatly appreciated!
Thanks!
Tym!
Make love, not chocolate chip cookies with nuts.
At least make the cookies without nuts for crying out loud.
|
|
|
|
|
It's too damned early for me to really play with this too much, but my gut is telling me you should be using a byte array (byte[]) rather than a String/StringBuilder. Reason being that the LPSTR in the MIDIHDR is really a char* (read:byte array). Have you taken a stab at using byte arrays yet? You may not even need the MarshalAs attribute in that case...not sure.
Jeremy Kimball
|
|
|
|
|
Thanks for the advice. I was leaning that way, I got as far as using a byte array, but still using the marshalling attribute, which gave me a runtime error.
I think you will prove to be right, it makes sense.
Thanks again, I'll let ya know if it works when I get a chance to try it...
Tym!
|
|
|
|
|
Still can't get it to work...
I have tried combinations of :
byte[]
char[]
String
StringBuilder
no MarshalAs
MarshalAs LPStr, ByValTStr
but I get the following error each time except when building the buffer with a StringBuilder and declaring data as a string, don't need any marshalling:
MIDIHDR can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed.
I'm thinking I just need build the string differently, so I'm gonna see what I can find on StringBuilder and hope it gets me somewhere.
Thanks!
|
|
|
|
|
Greetings!
How do I rename a file using C#? Does Anybody know how? Please help.
And also, how do I delete files or move them from folder to folder? Please help.
"To teach is to learn twice"
|
|
|
|
|
|
Say I have a string that's "C:\Folder\New\Filename.jpg"
Is there a built in method that will just let me rip the string to "Filename.jpg" or do I need to go through it manually?
|
|
|
|
|
Take a look at the System.IO.Path class and the GetFileName method.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Awesome, Was not aware of that class. Thanks for the tip!
|
|
|
|
|
Finding stuff in the framework classes is often the most challenging task working with C# .
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Reading is harder than typing? I think not. Back in the 1.0 beta days I spent time and at least skimmed through the BCL to see what's available. No one can memorize everything, but at least it gives you a good idea of where to look. Again, this is just laziness bolstered by IntelliSense!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I guess I'm remembering what it was like being a Java and C++ developer starting to learn C#. The language was easy to pick up, but figuring out where things are and the overall organization of the .Net Framework in general can take a little while to pick up.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Heath Stewart wrote:
this is just laziness bolstered by IntelliSense
Thats just what I was thinking )
IntelliSense is a great idea but it does almost remove any need to remember class and method names!
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
The following will work as well.
string full_path = @"C:\Folder\New\FileName.jpg";
string file_name = full_path.Substring(full_path.LastIndexOf(@"\") + 1);
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
Until you use this on a different platform. You should use Path.GetFileName . If you want to do such things yourself, be sure to at least use
Path.DirectorySeparatorChar<br /> .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi
Simple question: How can I block the user from moving a form around (i.e. making it stay in the same place all the time)?
I can't find a property/method for it in System.Windows.Forms.Form.
Naturally, I can just create an eventhandler for the LocationChanged event or similiar - but I'm looking for something a little more simple, since there are a lot of forms in our application which are all created by a form factory class.
Thanks for your help,
Mads
|
|
|
|
|
If it shouldn't be moveable then it shouldn't have a caption either. If make it FormBorderStyle.None it will have no caption or border and the user will not be able to drag it.
Obviously this is only suitable for special purpose applications that are designed to work on a dedicated computer, like a point of sale machine or kiosk. If you are writing a conventional application you should not be making for forms unmovable in the first place, that is exceedingly rude.
-Blake
|
|
|
|
|
FormBorderStyle.None is not good since that will remove both the caption and the border <=> the form will look rather silly.
Instead, our designgroup (sigh!) got another idea. They want the forms to have a caption with only a minimize button (i.e. no maximize and close buttons). Does any of you know if this is possible?
I have found e.g. form.MinimizeBox = false - but that property doesn't remove the button, it only disable it.
Again thanks for your help, Mads
BTW: It is actually a point of sale application, so we are not being rude
|
|
|
|
|
The whole point is, if you have a standard caption across the top of a form then then user is going to assume he can grab and drag it to move the form. Displaying a caption but then refusing to drag is just a way to piss off the user.
Use FormBorderStyle.None as I said and draw your own psuedo-caption across the top, with whatever controls you do or don't want in it. Do not give the user standard widgets and then make them not work, that is horrible UI design.
-Blake
|
|
|
|
|
Hello, Sir
I have a class that has two ImageList and two ImageIndex property as the code below.
My problem is when set propertyGrid.SelectedObject equal to my class instance
indexA and indexB will show the same list of images on the propertyGrid.
How to make the indexA show list of images in _imagelistA
and make the indexB show list of images in _imagelistB ?
Thank You.
Sorry for bad English.
public ImageList imagelistA
{
get { return _imagelistA;}
set { _imagelistA = value; }
}
[TypeConverter(typeof(ImageIndexConverter)), Editor("System.Windows.Forms.Design.ImageIndexEditor, System.Design,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",typeof(System.Drawing.Design.UITypeEditor))]
public int indexA
{
get { return _indexA; }
set { _indexA = value; }
}
public ImageList imagelistB
{
get { return _imagelistB;}
set { _imagelistB = value; }
}
[TypeConverter(typeof(ImageIndexConverter)), Editor("System.Windows.Forms.Design.ImageIndexEditor, System.Design,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",typeof(System.Drawing.Design.UITypeEditor))]
public int indexB
{
get { return _indexB; }
set { _indexB = value; }
}
|
|
|
|
|
I already replied to you about this. If you don't like the answer, sorry...but tough. The TypeConverter you're trying to use looks for the first property that returns an ImageList . That's why you see the same ImageList for both indexes. You're going to have to write your own. There's no way around it.
Read the documentation for the TypeConverter . It's actually not that hard. If nothing else, teach yourself IL and use ildasm.exe to look at the ImageIndexEditor and ImageIndexConverter (or use a decompiler like .NET Reflector) and change what you have to into your own class, attributing your property as you did above except with your own converter and editor (use the typeof operator if they are in the same assembly).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have 2 forms. The application enters on frmMain. Then I want to show frmSetup and hide frmMain.
it seems pretty straight forward, but i can not get frmMain to hide.
FormSetup frmSetup = new FormSetup();<br />
frmSetup.Show();<br />
frmMain.Hide();
is there anything i'm missing here?
|
|
|
|
|
Is that code placed in frmMain_Load? .NET shows a form after calling the Load-event, so hiding a form on load is ignored.
|
|
|
|