|
There are loads of examples of 'Drawing Board' or UML type apps, both of which use some of the techniques you will need. Try googling for 'UML c#'
or 'drawing board c#'.
An alternative is 'network graph c#', although that does not get such relevant results.
Tell you what, try some for yourself, while you're waiting for someone to come up with a better answer.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
I need to build a datagrid dynamically, entirely in c# so no asp tags can be used.
I need my datagrid to contain a textbox in each cell; pre-populated with the corresponding value from the datatable.
My code creates the text box in each cell perfectly BUT every value in the columns is the value of the last cell in that column of the datagrid.
The InstantiateIn method doesn’t seem to be being called for each row and only runs once for the last row. I can’t figure it out....
I pretty inexperienced with c# so any answers would be most appreciated.
Please help.
Thanks,
Jules
//---------------My c# Code Behind file--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_init(object sender, EventArgs e)
{
GenerateDataGrids();
if (!Page.IsPostBack)
{ }
}
public void GenerateDataGrids()
{
//-- Instantiate the data set and table
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add();
//-- Add columns to the data table
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Book", typeof(string));
dt.Columns.Add("Author", typeof(string));
//-- Add rows to the data table
dt.Rows.Add(1, "1984", "George Orwell");
dt.Rows.Add(2, "Notes from the Underground", "Fydor Dostoyevsky");
dt.Rows.Add(3, "The Outsider", "Albert Camus");
dt.Rows.Add(4, "Post Office", "Charles Buchowski");
dt.Rows.Add(5, "The Chant of Maldoror", "Comte De Lautremont");
DataGrid dg = new DataGrid();
dg.ID = ID;
dg.DataSource = ds;
dg.AutoGenerateColumns = false;
DataTable Workdt = new DataTable();
Workdt = ds.Tables[0];
for (int i = 0; i <= dt.Columns.Count - 1; i++)
{
// Creating Template Column
TemplateColumn tc = new TemplateColumn();
string columnName = dt.Columns[i].ColumnName;
tc.HeaderTemplate = new DataGridTemplate(ListItemType.Header, columnName);
for (int j = 1; j <= dt.Rows.Count - 1; j++)
{
string RowCallName = dt.Rows[j][i].ToString();
tc.ItemTemplate = new DataGridTemplate(ListItemType.EditItem, RowCallName);
}
dg.Columns.Add(tc);
}
dg.DataBind();
form1.Controls.Add(dg);
}
}
public class DataGridTemplate : ITemplate
{
ListItemType templateType;
string columnName;
public DataGridTemplate(ListItemType type, string colname)
{
templateType = type;
columnName = colname;
}
public void InstantiateIn(System.Web.UI.Control container)
{
Literal lc = new Literal();
switch (templateType)
{
case ListItemType.Header:
lc.Text = "" + columnName + "";
container.Controls.Add(lc);
break;
case ListItemType.Item:
lc.Text = "Item " + columnName;
container.Controls.Add(lc);
break;
case ListItemType.EditItem:
TextBox tb = new TextBox();
tb.Text = columnName;
container.Controls.Add(tb);
break;
case ListItemType.Footer:
lc.Text = "" + columnName + "";
container.Controls.Add(lc);
break;
}
}
}
]]>
]]>
<title>
|
|
|
|
|
I spotted one bug in your code:
you are looping through columns, and for each column you are looping the rows, so tc.ItemTemplate = new DataGridTemplate(ListItemType.EditItem, RowCallName); gets updated for each row, but it is used only one time, after exiting the loop, so last value of tc.ItemTemplate is the last row value.
Calin
|
|
|
|
|
You cannot do this using tc.ItemTemplate , you are not using it correctly. ItemTemplate is used to specify the template of a column, so you cannot specify 5 templates (for 5 rows) - for the same column.
Anyway, the colums templates are defined ok, but the binding is wrong.
Calin
|
|
|
|
|
Hello,
I am trying to initialize a jagged array as shown below. "Screen2 button IDs" and "Screen3 button IDs" arrays are a replica of the "Default screen button IDs" array. I was hoping to find a way where I can declare and initialize a 1-dimensional array similar to the "Default screen button IDs" one then use this array in my jagged array initialization. This will help me preserve some space and make the array look shorter. Any advice on how to achieve this?
Thanks,
<pre>BUTTON_ID[][] CONTEXT_MENU_LIST = new BUTTON_ID[][]
{
//System off
new BUTTON_ID[]{BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE},
//Default Screen button IDs
new BUTTON_ID[] {BUTTON_ID.DEFAULT, BUTTON_ID.EXAMINE, BUTTON_ID.CLIP,
BUTTON_ID.GAIN, BUTTON_ID.PAGE1, BUTTON_ID.FROZEN,
BUTTON_ID.SAVE, BUTTON_ID.PAGE2, BUTTON_ID.INACTIVE,
BUTTON_ID.DECREASE_LENGTH, BUTTON_ID.INCREASE_LENGTH,
BUTTON_ID.DECREASE_WIDTH, BUTTON_ID.INCREASE_WIDTH},
//Clip View Screen
new BUTTON_ID[] {BUTTON_ID.INACTIVE, BUTTON_ID.PAGE1, BUTTON_ID.FROZEN,
BUTTON_ID.AUTO_GAIN, BUTTON_ID.CLIP, BUTTON_ID.INACTIVE,
BUTTON_ID.SAVE, BUTTON_ID.PAGE2, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE}
//Screen2 button IDs
new BUTTON_ID[] {BUTTON_ID.DEFAULT, BUTTON_ID.EXAMINE, BUTTON_ID.CLIP,
BUTTON_ID.GAIN, BUTTON_ID.PAGE1, BUTTON_ID.FROZEN,
BUTTON_ID.SAVE, BUTTON_ID.PAGE2, BUTTON_ID.INACTIVE,
BUTTON_ID.DECREASE_LENGTH, BUTTON_ID.INCREASE_LENGTH,
BUTTON_ID.DECREASE_WIDTH, BUTTON_ID.INCREASE_WIDTH}
//Screen3 button IDs
new BUTTON_ID[] {BUTTON_ID.DEFAULT, BUTTON_ID.EXAMINE, BUTTON_ID.CLIP,
BUTTON_ID.GAIN, BUTTON_ID.PAGE1, BUTTON_ID.FROZEN,
BUTTON_ID.SAVE, BUTTON_ID.PAGE2, BUTTON_ID.INACTIVE,
BUTTON_ID.DECREASE_LENGTH, BUTTON_ID.INCREASE_LENGTH,
BUTTON_ID.DECREASE_WIDTH, BUTTON_ID.INCREASE_WIDTH}
};</pre>
|
|
|
|
|
Just place it in a temporary variable first?
warning: untested
BUTTON_ID[] defaultids = new BUTTON_ID[] {BUTTON_ID.DEFAULT, BUTTON_ID.EXAMINE, BUTTON_ID.CLIP,
BUTTON_ID.GAIN, BUTTON_ID.PAGE1, BUTTON_ID.FROZEN,
BUTTON_ID.SAVE, BUTTON_ID.PAGE2, BUTTON_ID.INACTIVE,
BUTTON_ID.DECREASE_LENGTH, BUTTON_ID.INCREASE_LENGTH,
BUTTON_ID.DECREASE_WIDTH, BUTTON_ID.INCREASE_WIDTH};
BUTTON_ID[][] CONTEXT_MENU_LIST = new BUTTON_ID[][]
{
new BUTTON_ID[]{BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE},
defaultids,
new BUTTON_ID[] {BUTTON_ID.INACTIVE, BUTTON_ID.PAGE1, BUTTON_ID.FROZEN,
BUTTON_ID.AUTO_GAIN, BUTTON_ID.CLIP, BUTTON_ID.INACTIVE,
BUTTON_ID.SAVE, BUTTON_ID.PAGE2, BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE, BUTTON_ID.INACTIVE,BUTTON_ID.INACTIVE,
BUTTON_ID.INACTIVE},
defaultids,
defaultids
};
|
|
|
|
|
I already tried that and got the following error message: "A field initializer cannot reference the non-static field, method, or property"
|
|
|
|
|
Make the temporary thing static?
|
|
|
|
|
harold aptroot wrote: temporary thing
... the latest buzzwords always confuse me
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Ok better idea: initialize it in the constructor.
|
|
|
|
|
That works like a charm. Would you please explain to me what did the static keyword change in this case?
Appreciated,
|
|
|
|
|
It cheated. I'm afraid I suggested an ugly work-around that is at least "bad taste".
Oh well. An explanation.
It made the "temporary" object static. That is, it is shared between all instances of the containing class (or struct). It shouldn't be (shared, that is), but it works.. But it also has the unfortunate side effect that a reference to that array is kept - forever (well, at least for a long time).
I was partially under the impression that this initialization code was for a local variable, if that were true there would be no need of such ugly hacks.
And I should have suggested something better, which I did later.. Initializing that field in the constructor.
Now, I just realized something. Code like that should almost never initialize a non-static field. Because it looks like that (jagged) array is meant to be a look-up table. If it isn't then don't worry about it, but if it is, consider making it static as well. Or even static readonly. But what am I saying here, it's your code after all and I don't know how you're using it. Do what you want
|
|
|
|
|
harold aptroot wrote: It cheated. I'm afraid I suggested an ugly work-around that is at least "bad taste".
Oh well. An explanation.
It made the "temporary" object static. That is, it is shared between all instances of the containing class (or struct). It shouldn't be (shared, that is), but it works.. But it also has the unfortunate side effect that a reference to that array is kept - forever (well, at least for a long time).
I was partially under the impression that this initialization code was for a local variable, if that were true there would be no need of such ugly hacks.
And I should have suggested something better, which I did later.. Initializing that field in the constructor.
Now, I just realized something. Code like that should almost never initialize a non-static field. Because it looks like that (jagged) array is meant to be a look-up table. If it isn't then don't worry about it, but if it is, consider making it static as well. Or even static readonly. But what am I saying here, it's your code after all and I don't know how you're using it. Do what you want Smile
I see what you mean now. The thing is I am using the jagged array as an LUT. I tried to make it static but it didn't initialize properly. I looked into the Dictionary data structure and figured out that it won't work for me. I guess I have to deal with this flaw for now. Thanks Harold for your support with this issue.
|
|
|
|
|
Hi,
if you have a non-static solution that works, and everything is read-only anyway, then you can modify it to all-static; the initialization code should go either in the normal constructor (just test whether the static stuff is still null, and initialize if it is) or start using a "static constructor".
That will save a lot of bytes and cycles, depending on the size of the jagged array and the number of class instances.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:19 AM
|
|
|
|
|
Hi all
My problem that i have is that i have written code to do
word rapping on a string to fit on a print document
My print document has a margin bound of a hundred(100)
Basically i have a
627 line with and
969 page height
and printing with Ariel 10pt.
My Word wrapping code wraps on a space or a \n
and I'm sitting with the problem that the rich text box does
not do the same wrapping
my rich text box font has also been set to Ariel 10pt.
one thing that if have noticed that it looks like the is a font issue
Any Help Would be greatly appreciated
Ps. have searched for something similar but with no luck
|
|
|
|
|
The only way to achieve what you want is to do the string calculation for the printer and try to calculate what the size of the RichTextBox should be to get the same effect.
The RTB is NOT a WYSIWYG control...
|
|
|
|
|
Hi all,
Can anyone tell me that how can i fire drop event of richtext box in .net2.0?I mean in my application i need to drag some data from list box and drop into rich text box.
Thanks in advance
Lijo
|
|
|
|
|
To allow drop in the RichTextBox, you have to set RichTextBox's AllowDrop property to true. Then you can handle DragEnter,DragDrop and DragOver Events.
|
|
|
|
|
Hii
everybody,
i am developing window application in c# and .net and i want to know that how to write a join query for update of local database by the content of remote server database!.
Scenario :- Suppose there is one database say softbuyweb at local machine and other database softbuyweb1 at remote server.
now there is table in softbuyweb say product and similarly there is table in softbuyweb1 say product1
now both the table product and product1 in database softbuyweb and softbuyweb1 respectively has same column/field name, datatype and length of datatype.
now i want that in my window form i place one button say "Update" on its click event there should be query which fires and the total content of table product1 at remote server is copied and the content of table product at local machine is updated with that copied content.
i think it is little confusing and also it may be difficult to write single sql query for two different data sorce connection and it might create ambiguity because both connection are establishes in a single block of code.
now , please help me on this topic , and please response as qick as possible!
my database is in sql server 2005.
thanx in advance.
|
|
|
|
|
The easiest way would be to link the SQL Server databases together so you could use an UPDATE FROM statement(Those things are like magic)
Beyond that and using any sort of Database specific synchronization open a cursor, compare records, and update the outdated db.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: UPDATE FROM
Ennis can you elaborate on this. Is it like the select into shortcut for creating tables?
Wondering if I have missed something all these years?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
UPDATE customer
SET customer.firstName = remoteCustomer.firstName
FROM customer
INNER JOIN remoteCustomer ON
remoteCustomer.id = customer.Id
AND remoteCustomer.GUID <> customer.GUID;
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Thanks Ennis
Nothing new there, just thought there might have been something quite different. Sometimes I come across something in the forums completely new in a tool I have been using for ages (eq SQL).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hi all
i want to access gmail programatically using c#.
i will just enter my email id & password. if the email id & password is true then the server will give me a response.
but its giving me error the remote server returned an error 403
pls help me
thanks in advance
NameValueCollection nvc = new NameValueCollection();
nvc.Add("accountType", "HOSTED_OR_GOOGLE");
nvc.Add("Email", "dllcheck@gmail.com");
nvc.Add("Passwd", "dllcheck123");
nvc.Add("service", "cl");
nvc.Add("source", "Gulp-CalGulp-1.05");
WebClient client = new WebClient();
byte[] Response = client.UploadValues("http://www.google.com/accounts/ClientLogin",nvc);
string s = Encoding.Default.GetString(Response);
MessageBox.Show(s);
// http://www.google.com/accounts/ClientLogin/accountType=HOSTED_OR_GOOGLE&Email=jondoe@gmail.com&Passwd=north23AZ&service=cl&source=Gulp-CalGulp-1.05
HttpWebRequest webreqAuthenticate = (HttpWebRequest)WebRequest.Create("http://www.google.com/accounts/ClientLogin");
webreqAuthenticate.ContentType = "application/x-www-form-urlencoded";
webreqAuthenticate.Method = "POST";
webreqAuthenticate.ContentLength = 200;
//webreqAuthenticate.Timeout = 6000;
webreqAuthenticate.AllowAutoRedirect = true;
webreqAuthenticate.MaximumAutomaticRedirections = 10;
HttpWebResponse webresAuthenticate = webreqAuthenticate.GetResponse() as HttpWebResponse;
Stream streamResponse = webresAuthenticate.GetResponseStream();
|
|
|
|
|
There are existing solutions for accessing Gmail from C#:
Click[^]
|
|
|
|
|