|
If you have a syntax that allows me to retrieve the index of elements in a ListBox, its me far enough. Thank you
|
|
|
|
|
Go out and buy an introductory book on C#. Study that for one week and you will leap ahead.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I want to know how can i get the number of times a window has been visited
|
|
|
|
|
You would need to write code to track that value yourself.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You can use a class level static integer variable for this. Increment it in the load event of your form. If you need the value next time the application is opened, either save it in database or in config file or in registry.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hi All,
Is there anyone in here have some sort of expeience with Janus Grid, if you do, can you please read through.
This is about format a cell in Janus Grid, such as:
GridEXFormatCondition fco = new GridEXFormatCondition(
this.gridEX1.RootTable.Columns[4],
ConditionOperator.Equal, true);
fco.TargetColumn = this.gridEX1.RootTable.Columns[4];
fco.TargetColumn.CellStyle.BackColor = Color.LightYellow;
This piece of code formats the back color of whole Columns[4] to light yellow, now what i really want is to format a cell, rather than the whole Columns[4] to light yellow.
If someone in here can shed me a light will be great.
|
|
|
|
|
Dont worry, guys, I already worked it out myself. here is the solutionif anyone come across the same issue next time:
basically once the target column be pointed, then the fco applys on that sepcific cell when condition meets:
GridEXFormatCondition fco = new GridEXFormatCondition(
this.gridEX1.RootTable.Columns[4],
ConditionOperator.Equal, true);
fco.TargetColumn = this.gridEX1.RootTable.Columns[4];
fco.FormatStyle.BackColor = Color.LightYellow;
|
|
|
|
|
Hi.
i face a Error
Unable to cast object of type 'System.Windows.Forms.TextBox' to type 'System.IConvertible'.
When I Do this
int ProdTotal=0;
ConTotalTxt.Text = Convert.ToString(Convert.ToInt32(ProdTotTxt) + ProdTotal);
in this code where i do mistak???
thanks in Advance
Jawad Khatri
|
|
|
|
|
What is the type of ProdTotTxt ? If it is a textbox, you need to write like ProdTotTxt.Text
Best wishes,
Navaneeth
|
|
|
|
|
oohhh...Sorry ..
you right
thanks Sir
|
|
|
|
|
I'm having trouble implementing a depth chart for my football simulator program. The way my program is structured, I have a Player class, a Team class, and a League class--the core classes. The depthchart would group players by their position and, by each position, sort by OVR (integer) in descending order (but only if their injury status is "false"--governed by a CanPlay method in my Player class; otherwise, they are not eligible for the depthchart). Position is a PlayerPosition type and PlayerPosition is enumerated as such:
[code]
public enum PlayerPosition { QB, HB, WR, TE, LT, LG, C, RG, RT, DE, DT, OLB, MLB, CB, FS, SS }
[/code]
This is in my Team class:
[code]
public List<Player> depthChart { get; set; }
public List<Player>[] DepthChart
{
get
{
var result = new List<Player>[Enum.GetValues(typeof(PlayerPosition)).Length];
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
result[(int)pos] = this.Players.Where(pl => pl.position == pos && pl.CanPlay).OrderByDescending(pl => pl.OVR).ToList();
}
return result;
}
[/code]
These are in my Main() method: two attempts to obtain information from the depth chart.
Method 1:
[code]
Team t = league.Teams[0];
var depthChart = t.DepthChart;
Console.WriteLine(depthChart);
[/code]
Method 2: prints out the entire depth chart, not just the starter.
[code]
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
Console.Write(pos.ToString() + ':');
depthChart[(int)pos].ForEach(p => Console.Write(' ' + p.lastName));
Console.WriteLine();
}
[/code]
For method 1, I get on the console readout: System.Collections.Generic.List`1[FranchiseSim.Player][]
For method 2, I get on the console readout only the proper position strings (like QB, RB, etc.) and the colon ( but nothing from the depth chart.
|
|
|
|
|
Hi All,
I did raise this question yesterday also, but its not showing up in the message board, thus pasting it again.
I have a DataGridView where in I am trying to add DataGridViewComboBoxColumn. Though the column is getting added but the combobox is empty.
<br />
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();<br />
cell.Items.Add("One");<br />
cell.Items.Add("Two");<br />
cell.Items.Add("Three");<br />
DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();<br />
column.HeaderText = "SELECT";<br />
column.Name = "ItemSelect";<br />
column.CellTemplate = cell;<br />
column.DropDownWidth = 160;<br />
column.Width = 90;<br />
column.MaxDropDownItems = 3;<br />
column.FlatStyle = FlatStyle.Flat;<br />
column.ReadOnly = true;<br />
myDataGridView.Columns.Insert(0, column);<br />
After displaying the values which event I should handle to get the selected value in combobox?
Thanks in Advance
|
|
|
|
|
Hi All,
I have rows and columns of rectangles which act as a rack system. Please see the attached picture.
http://i446.photobucket.com/albums/qq185/toe_toe7/C%20Sharp/test.jpg[^]
What I am trying to do now is as follow:
1. Left click to select single rectangle
2. Ctrl+Left click to select multiple rectangles one by one
3. Drag and create a boundary to select multiple rectangles within the boundary.
And after selecting, I would need to return the selected rectangles value.
I was told to use ILOG but I just wonder if it could be done without it.
Thanks in advance..
|
|
|
|
|
Your best bet is to keep an array of rectangles to draw, draw them in your paint event, and as you drag a box, iterate over your collection of boxes and work out which ones are inside that box, and mark them accordingly
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
How to Create Parent Node and child Node Automatically?
that means the nodes Generation from the Fields of database?
thanks!
|
|
|
|
|
Nothing is automatic, and anything that is automatic should be avoided.
Roll your own.
|
|
|
|
|
table A Id Name
1 John
2 Mary
table B Id A.Id content
1 2 aboult Mary
2 1 aboult John
query:
Mary aboult Mary
John aboult John
name modified
table A Id Name
1 Mary
2 John
query again:
Mary aboult Join
John aboult Mary
The result is error!
How to design?
modified on Monday, November 9, 2009 9:46 PM
|
|
|
|
|
I can't make sense of this, is it a SQL question ? What are you asking ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Never change the ID of an object. IDs should be completely meaningless values. There should never be a desire to change an ID.
|
|
|
|
|
Please take a look at the code below ...
NOTE: [never mind square brackets, it is ment to be a list]
/*
my solution (not exacly what I need)
*/
Class Graph
{
int void ShortestPath(int SN, int StN)
{
...
List[int] GoThroughNode = new List[int]();
Path result = new Path();
result.printGoThroughNode(GoThroughNode);
}
}
class Path
{
public void printGoThroughNode(List[int] GTN)
{
foreach (int item in GTN)
{
Console.Write(item);
}
}
}
...
/*
so for every method in Class Path, in order to receive List[int]GoThroughNode(), i have to refer to result object in int void ShortestPath().
What I want is to get method(which contains List[int]GoThroughNode) from Class Graphs to use it in Class Path;
*/
modified on Monday, November 9, 2009 10:12 PM
|
|
|
|
|
Not very clear what do you mean by "get method(which contains List[int]GoThroughNode) from Class Graphs to use it in Class Path"
Do you want something like Graph.GoThroughNode?
|
|
|
|
|
basicly what i want is:
in class Path to make method Print(), which receives list<int> GoThroughNode from method ShortestPath() which is in class Graph.
So I could call Print() from static void Main() when I need to.
The problem is solved in my code, yes, but I also need class Path to be able to use that received list<int> GoThroughNode for other methods also, not only for method Print().
|
|
|
|
|
Here is a block of code that copies a file:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string[] src = e.Argument as string[];
cnt = 0;
while (cnt < src.Length && src[cnt] != null)
{
toolStripStatusLabel1.Text = "Copying " + src[cnt] + "...";
string[] words = src[cnt].Split('\\');
string dest = keeppath2 + "\\" + words[words.Length - 1];
if (dest.IndexOf(".") > -1)
{
FileStream inFile = new FileStream(src[cnt].ToString(), System.IO.FileMode.Open);
if (!System.IO.File.Exists(dest))
{
using (System.IO.FileStream fs = System.IO.File.Create(dest))
{
for (byte i = 0; i < 100; i++)
{
fs.WriteByte(i);
}
}
}
FileStream outFile = new FileStream(dest, System.IO.FileMode.Open);
long size = inFile.Length;
int lineSize = 1024 * 64;
long filesize1 = inFile.Position / 1024;
long filesize2 = inFile.Length / 1024;
byte[] buffer = new byte[lineSize];
while ((inFile.Read(buffer, 0, lineSize)) > 0)
{
outFile.Write(buffer, 0, lineSize);
filesize1 = inFile.Position / 1024;
toolStripStatusLabel1.Text = "Copying " + src[cnt] + "... " + filesize1 + "KB of " + filesize2 + "KB";
}
outFile.Flush();
outFile.Close();
inFile.Flush();
inFile.Close();
}
else
{
try
{
copyDirectory(src[cnt].ToString(), dest, toolStripStatusLabel1);
}
catch (Exception error)
{
}
}
cnt++;
}
}
Every once in a while I get this error when copying:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.ToolStripItem.get_ContentRectangle()
at System.Windows.Forms.ToolStripSystemRenderer.RenderLabelInternal(ToolStripItemRenderEventArgs e)
at System.Windows.Forms.ToolStripSystemRenderer.OnRenderToolStripStatusLabelBackground(ToolStripItemRenderEventArgs e)
at System.Windows.Forms.ToolStripRenderer.DrawToolStripStatusLabelBackground(ToolStripItemRenderEventArgs e)
at System.Windows.Forms.ToolStripStatusLabel.OnPaint(PaintEventArgs e)
at System.Windows.Forms.ToolStripItem.HandlePaint(PaintEventArgs e)
at System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.StatusStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:----------------------------------------
Filemon
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Does anyone know how to avoid this error?
I will also occasionally get this error:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Windows.Forms.ToolStripItemCollection.get_Item(Int32 index)
at System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.StatusStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:----------------------------------------
Filemon
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Thanks for looking
|
|
|
|
|
Hi,
I see two errors:
1.
your DoWork() method contains accesses to toolStripStatusLabel1.Text which it shouldn't. AFAIK (documentation doesn't contain this) all GUI parts, not just Controls, are untouchable by another than the main thread. You could read this[^] for more; I believe ToopStrip parts need the same approach; however they don't offer InvokeRequired/Invoke, so you would have to borrow another Control on the same Form (or the Form itself).
This would be sufficient to explain most erratic behavior your app may show, especially regarding the GUI. It probably is sufficient to cause the problem you're having, however only fixing and testing will tell.
2.
in while ((inFile.Read(buffer, 0, lineSize)) > 0) the Read method returns the number of bytes read, which you test for non-zero, but you don't otherwise use it; you really should store the value in a variable and use that instead of linesize in outFile.Write(buffer, 0, lineSize); as the value may be different, especially at the end of the file.
I also have several comments:
3.
I think a foreach would be much more elegant than while (cnt < src.Length && src[cnt] != null)
4.
when the destination file does not exist, you create a dummy one first; I see no use for that.
5.
you are reporting progress inside your copy loop; that will probably slow down the operation npticeably; I suggest you display the sizes in MB, not KB, and only update the GUI when the number has changed.
6.
you have some Flush-and-Close sequences; they don't make much sense, Close() implies Flush().
7.
you don't create the destination folder; if it does not exist, your app will fail copying files to it. A simple Directory.Create() would do, no need to test for existence. You must calculate the path though. The Path class has methods for that.
8.
I saw an empty catch block; that is a very bad idea as it hides potential problems. You should only catch what you can handle (i.e. solve) and leave the rest to the caller; alternatively, you should log the problem, but never let it disappear without treatment.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Wow, thanks for the advice! This is my first c# program. I implemented your fix for the second problem but you are telling me that I cannot alter a status label from another thread at all? How would I show copy progress, with a messagebox instead?
|
|
|
|
|