|
The two answers above me are correct in different cases. If the DropDownStyle is DropDown (i.e. drop/edit), set the Text property to have an initial value. If it is DropDownList, set SelectedIndex (or SelectedItem). You should do this after InitialiseComponent is called; I typically do it lower down in the form class constructor.
Alternatively, if you data bind the combos, they will initialise to the initial value of the property to which they are bound.
|
|
|
|
|
this code may help you..
private void loadComboBox()
{
if (this.cmb.DataSource == null)
{
this.cmb.Items.Add("Please Wait");
this.cmb.Text = "Please Wait";
this.cmb.Refresh();
}
DataTable tbl = comboData() as DataTable;
tbl.Rows.Add(0, "<Select>");
cmb.DataSource = tbl;
cmb.DisplayMember = "Name";
cmb.ValueMember = "Id";
cmb.SelectedValue = 0;
}
|
|
|
|
|
HI,
I have arraylist and the first item in array represent time , the number of message in array may be reach up to 10,000 messages , so if I have messages reached to 2000 message the message number 20001 is set to 0 and when I try to get the total time I have problem because the total is the final element.
some issues :-
- if message set to zero after number of message I will consider the past time is 3640 seconds and so on.
total time = 3640 + the last element in the last in the next items.
- if number of message not set to zero the end item will represent the total time.
<br />
for (int j = 0; j < numberOfMessagesInSection; j++)<br />
{<br />
<br />
nextValue = int.Parse(MessageTimeAssociation[next + 1].messagebytes[0]);<br />
<br />
if (nextValue >= int.Parse(MessageTimeAssociation[j].messagebytes[0]))<br />
{<br />
totalSectionTime = int.Parse(MessageTimeAssociation[numberOfMessagesInSection - 1].messagebytes[0]);<br />
<br />
}<br />
else<br />
{<br />
<br />
totalSectionTime += 3640;<br />
<br />
}<br />
this my code but my problems appears in this cases :-
if the arraylist contains few messages the total time should be the final element but this code not achieve it.
|
|
|
|
|
This has a bad code smell about it that can be detected from the moon, and that's made of cheese.
Honeyboy_20 wrote: I have problem because the total is the final element.
So don't do that then.
The main problem with this is how you are representing your data: ArrayList has almost zero use since generics came out. You might need a List<Message> or HashSet<Message> or possibly Queue<Message> it depends on what you are doing, even then other collections might be more appropriate. In any case storing multiple object types the way you have described it in an ArrayList is a recipe for disaster, you should:
Create a new class to store your data
Add the appropriate Generic collection as a property (make the property read-only: you can still add items externally)
Add properties to store any timings you need
I don't fully understand your problem, but whatever it is this should provide a start.
|
|
|
|
|
I ask about condition as logical if you can help ok or stop.
|
|
|
|
|
His answer is valid. Your code doesn't make any sense at all and your description of the problem only adds to the confusion. How does the number of bytes in a message relate to a time value? Why?
|
|
|
|
|
He was being helpful. Keith is one of the good guys. I wouldn't have been as gentle.
Rather than throwing a hissy fit, you should ask yourself why he replied in this manner. Perhaps then you could actually learn and grow as a developer.
|
|
|
|
|
Thats one of the things I like about the code project, you might not get the answer you want but someone will give you the answer you need.
I doubt anyone will understand what you wanted, it certainly isn't clear from the code. When this happens, irrespective of who writes it, it means than more than likely the code has a design flaw. Fix the design flaw first and quite often the problem you are having dissapears or become easy to spot.
|
|
|
|
|
Stop being an ass hat...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Keith Barrow wrote: that's made of cheese
limburger?
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Where did the 'next' and 'numberOfMessagesInSection' come from?
You're using it in the statment but none of us know how they are declared or how they're being used.
|
|
|
|
|
I was confused when I read this question the first time.
Then I was even more confused when I read it the second time.
I don´t like to read this question a third time.
I cannot remember: What did I before google?
|
|
|
|
|
Dear all
I am brand new to C# and have previously only written programs in Javascript, so go easy on me !
I have written an "app launcher" program which reads a text file line by line. Each line is just a path to a program e.g. C:\Users\Matt\Desktop\Gravity.exe
So far, my program can successfully read each line and produce a list of links. As intended, each link appears as the path itself.
The problem I am having is that these links will not work. However they WILL work if they are all just given the same fixed path. I would like each link to use its .Text property as the destination. (please see the comments "works" and "does not work" in my code below). The only error I get is "cannot find the file specified".
I would really appreciate any help on this as I am finding C a lot harder than Javascript !
Thank you
Jim
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO; //for reading a text file
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) //on form load
{
int counter = 0;
string line;
string myfile = @"c:\users\matt\desktop\file.txt";
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(myfile);
while ((line = file.ReadLine()) != null)
{
//MessageBox.Show(line); //check whats on each line
LinkLabel mylinklabel = new LinkLabel(); //LinkLabel tells us the type of the object e.g. string mystring ="hello";
mylinklabel.Text = line;
this.Controls.Add(mylinklabel);
mylinklabel.Location = new Point(0, 30 + counter * 30);
mylinklabel.Click += new System.EventHandler(LinkClick);
counter++;
}
file.Close();
}
private void LinkClick(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start(this.Text); //doesn't work
//System.Diagnostics.Process.Start(@"C:\Users\Matt\Desktop\gravity.exe"); //works
}
}
}
|
|
|
|
|
Hi,
welcome to CodeProject.
Please use PRE tags correctly to show code snippets. You could still edit the existing message.
Your problem is this:
in System.Diagnostics.Process.Start(this.Text); this refers to the instance of the class it is in, i.e. to your Form, and not to the specific LinkLabel you are hoping it refers to. To get that, try this:
LinkLabel link=sender as LinkLabel;
if (link!=null) System.Diagnostics.Process.Start(link.Text);
I also suggest you add some error handling, so you get a decent response when the file doesn't exist.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Good answer. To provide a little more help to the newbie who asked the question: In C#, the convention (and what IDEs produce) is that event handlers are written in the form class, so this refers to the form and not to the source of the event. The sender parameter is the source of the event (e.target, to make a JavaScript analogy), but you will need to cast it to a type that you know it must be.
In addition, for event handlers which are fired only off one control, you can simply refer to that control in the event handler. E.g.
LinkLabel myLinkLabel;
Form1(){
myLinkLabel = new LinkLabel();
myLinkLabel.Text = "/thing.exe";
myLinkLabel.Click += (s,e) => {
Process.Start(((LinkLabel)s).Text);
};
}
(I wrote the event handler as a lambda delegate, for .Net 3.0 and up, but the same things apply if you write it as a normal method.)
Edit: ... but missed out the semicolon at the end of the delegate assignment.
modified on Tuesday, May 3, 2011 10:40 AM
|
|
|
|
|
See this wud work for sure
System.Diagnostics.Process.Start(((LinkLabel)sender).Text);
modified on Thursday, May 5, 2011 5:58 AM
|
|
|
|
|
It's bad enough having questions in txtspeak. Answers should be in grammatical English.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Sorry Sir i am just new at it
modified on Thursday, May 5, 2011 6:11 AM
|
|
|
|
|
Hello dear friends.
Thanks to Ranjan.D article about How To Send and Receive SMS using GSM Modem[^] I could modify his program and adapt it to my small application which needed to send a command line from a pc via sms to a digital device and this device will returns a value which is received in the PC and stored in a database.
The question is, how could I do to send this command via SMS to multiple devices and get all the answers you need in one pc.
I read something about "SMS Gateway" but the truth is that I'm not excited about the idea of having to make a payment for this service in addition to what I already paid to the telephone operator for the chip's and sending messages.
Whould you give some ideas????
|
|
|
|
|
when I have a BitmapSource I can easily
BitmapSource img = ...;
using (var stream = new FileStream("scene.png", FileMode.Create))
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(img));
encoder.Save(stream);
}
Unfortunately D3DImage is not a BitmapSource !
So.. how could I save my D3DImage to a PNG file?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
modified on Monday, May 2, 2011 1:37 PM
|
|
|
|
|
I'm using SharpDX[^] so I have a fully managed DirectX environment.
I figured it out!
Just for the info, here is how!
class Program
{
unsafe static void Main(string[] args)
{
using (var d3d2d = new D3D11_2D1())
{
d3d2d.Reset(250, 250);
var sc = new Scene_11() { Context = d3d2d.Drawing };
var scw = new SceneDwrite() { Context = d3d2d.Text };
var rargs = new RenderArgs();
d3d2d.BeginRender(rargs);
sc.Render(rargs);
scw.Render(rargs);
d3d2d.EndRender(rargs);
Save1(d3d2d);
}
}
unsafe private static void Save1(D3D11_2D1 d3d2d)
{
var wb = GetBitmap(d3d2d.Drawing.BackBuffer);
using (var stream = new FileStream("scene.png", FileMode.Create))
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(wb));
encoder.Save(stream);
}
}
unsafe private static void Save2(D3D11_2D1 d3d2d)
{
using (var teximg = GetCopy(d3d2d.Drawing.BackBuffer))
Resource.ToFile(teximg.Device.ImmediateContext, teximg, ImageFileFormat.Png, "scene.png");
}
unsafe private static WriteableBitmap GetBitmap(Texture2D tex)
{
int w = tex.Description.Width;
int h = tex.Description.Height;
var wb = new WriteableBitmap(w, h, 96.0, 96.0, PixelFormats.Bgra32, null);
wb.Lock();
uint* wbb = (uint*)wb.BackBuffer;
var db = GetDataBox(tex);
db.Data.Position = 0;
for (int y = 0; y < h; y++)
{
db.Data.Position = y * db.RowPitch;
for (int x = 0; x < w; x++)
{
var c = db.Data.Read<uint>();
wbb[y * w + x] = c;
}
}
wb.AddDirtyRect(new Int32Rect(0, 0, w, h));
wb.Unlock();
return wb;
}
private static DataBox GetDataBox(Texture2D tex)
{
var db = GetDataBox(tex, 1);
return GetDataBox(tex, tex.Description.Height * db.RowPitch);
}
private static DataBox GetDataBox(Texture2D tex, int size)
{
using (var teximg = GetCopy(tex))
return tex.Device.ImmediateContext.MapSubresource(
teximg
, 0
, size
, MapMode.Read
, MapFlags.None);
}
private static Texture2D GetCopy(Texture2D tex)
{
var textimgdesc = tex.Description;
textimgdesc.SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0);
textimgdesc.Usage = ResourceUsage.Staging;
textimgdesc.BindFlags = BindFlags.None;
textimgdesc.CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write;
var teximg = new Texture2D(tex.Device, textimgdesc);
tex.Device.ImmediateContext.CopyResource(tex, teximg);
return teximg;
}
}
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi Experts ,
Could you help me in using safeHandle instead of IntPtr.I am trying to fix CA2006 reliability warning, but MSDN is lacking of examples.
|
|
|
|
|
SafeHandle[^]
I know nothing , I know nothing ...
RIP Osama Bin Laden, you were thorn in USA throat ,
And you will always be ...
|
|
|
|
|
Bonjour,
je voudrai savoir comment enregistrer un chemin de fichier pdf dans la base de données.j'ai déja fait un code d' enregistrer mais au moment ou je clique sur le bouton "enregistrer, tous les autres champs s'ajoutent dans la base de données sql server 2008 sauf le chemin qui ne s'ajoute pas,son champs reste vide .voilà mon code du bouton enregistrer
try
{//je clique sur le bouton parcourir qui me permet de choisir le pdf à choisir et après son chemin s'affiche dans listbox
if (listBox1.Text == "" || txtLibellé.Text == "" || cbtheme.Text == "")
MessageBox.Show("remplisser d'abord les zones vides!!");
else if (o.Verifier(" Document ", " chemin ", listBox1.Text) == true)
{
MessageBox.Show("existe deja");
}
else
{
o.exec("Insert into Document Values ('" + listBox1.Text + "','" + txtLibellé.Text + "','" + dateTimePicker1.Text + "','" + cbtheme.Text + "')", false);
MessageBox.Show(" c'est enregistré!!!");
Liste();
o.ligne = o.dt.Rows.Count - 1;
}
}
catch (Exception Ex)
{
MessageBox.Show("" + Ex);
}
|
|
|
|
|
هذا الموقع بل الإنجليزية
Perhaps now you understand the importance of keeping the website in one Language, in our case English. This isn't the UN after all.
While we are at at it:
Marking something as urgent is rude (Read the FAQs) - it might be to you, it isn't to us, and we are unpaid.
You have not formatted the code so we can't read it (See the FAQs)
|
|
|
|
|