|
thanks to your reply,
i tried to use the items but i doesn't work because my combo is binded with a dataset
comboBox1.DisplayMember = "LIBL";
comboBox1.ValueMember = "ID";
comboBox1.DataSource = oDs.Tables[0];
the dataset is filled through a stored procedure
best regards,
fady
|
|
|
|
|
When you bind the data, the Items collection is populated. Then it doesn't matter where the data came from.
---
b { font-weight: normal; }
|
|
|
|
|
Could someone please give me an example in c# on capturing the right click and paste mouse events from any forms/applications. I can capture/monitor this using the keyboard but cannot do so when using mouse cut/copy and paste. Need help please.
I looked at the Globalhooksdemo (project in code project) in c# but only helped me on keyboard cut/copy and paste.
Thanks in advance
|
|
|
|
|
Hi,
I'm quite new to c# and windows.forms, so these are probably very basic questions
The first one is: what's the .net equivalent of ddx in mfc? Meaning, how do I associate the values of textboxes and checkboxes etc on forms with members of that forms? I've found ControlBindingsCollection and friends but that seems to be only for binding to databases, I want to bind to normal variables.
Secondly, in my dialog I have the following:
|---| |---|
| A | XXX | B |
|---| |---|
where the two squares A and B are list boxes and the XXX is a button. Now what I want is when the dialog is resized that the button stays the same size and that the two listboxes take up the rest of the space, so that the distance between the right of A and the left of the button stays the same, and the distance between the left of B and the right of the button stays the same as well. I cannot simply set the 'Anchor' property of A and B to 'Left,Top,Right' because that will make them overlap each other, which in turn is caused by the fact that the Anchor is relative to the parent container which is the dialog in this case. How do I do this? (Apart from overriding the dialog's OnSize and positioning everything manually).
cheers,
roel
|
|
|
|
|
Hi Roel,
First you have a much better option in c# than the one offered by MFC through the ddx functions. c# or .net controls on your form are true objects and not wrappers as in case of the of MFC. You could directly access the value of the control so in a sence there is no real need to have another variable in the form to store it. You could do something like TextBox.Text to access the value any time you want. However if you still wanted the MFC like functionality then you could probably hook the form validate event and code the actual transfer of data from control to variable manually. Why have this over head when you can access the values directly?
For the second problem you cannot do this through setting properties. You have to do this programatically.
Cheers,
Prady
|
|
|
|
|
Hello Pradyumna,
Thank you for your explanation. The reason I wanted to save to another variable was first because I thought that the controls would not be available anymore once the dialog is closed, and secondly because I'd like to encapsulate the type of control (if I decide to change a textbox with a combobox I'd have to go around around change calls to .Text with calls to .SelectedText). But I've found another way to encapsulate the functionality that I require in my dialog, so for now this problem is not relevant to me any more - but still, it's good to know for the future that there is no equivalent to ddx and that I'll have to save data manually.
As for the second part, that's too bad, I thought that with windows forms we'd have layout managers that would be just as powerful as those in eg Java's AWT or in the GTK toolkit. Looks like I was wrong
Thanks for your time!
cheers,
roel
|
|
|
|
|
Roel,
The version 2.0 for the .net framework has the layout mangers in the forms. So may be you can wait for that.
Prady
|
|
|
|
|
roel_ wrote:
As for the second part, that's too bad, I thought that with windows forms we'd have layout managers that would be just as powerful as those in eg Java's AWT or in the GTK toolkit. Looks like I was wrong
.net 2 is supposed to have a much more complete layout manager. Until then however you're stuck with doing it the hardway if you want anything complex.
|
|
|
|
|
I want to define an array and will redfine on recieving the values from database.But I dont know how to redefine the string array.
string[][] TestArray;
/// now how to define the dimensions like I want it this way after getting records--- TestArray[5][2] - which shows 5 records and two values + latter if I fetch more values the array should be redefined with last values saved + new added values which will make it like TestArray[10][2]
|
|
|
|
|
Try this:
string[,] TestArray;<br />
TestArray = new string[10,2];
Regards,
mav
|
|
|
|
|
Thanks it worked fine. One last thing how to preserve the previous values while re-defining the length. Like I am building this array in a while loop and on each turn I have to add one string node. but it initialize complete array every time.
Thanks in Advance
|
|
|
|
|
You can't change the size of an array. You could create a new array and copy everything from the old array, but that would be quite slow, and scales horribly bad.
Use an ArrayList or similar class, that has built in functionality to grow. As a list is one dimensional, you would put arrays in the list.
---
b { font-weight: normal; }
|
|
|
|
|
Hello Everyone!
I have two related table Customer and Address, one customer may have several address. The source database is in access. I use the following code to populate the dataset and define the relationship between customer table and address table.
<br />
cus_adaptr.SelectCommand = cn.CreateCommand();<br />
cus_adaptr.SelectCommand.CommandText = "Select * from Customer";<br />
cus_adaptr.MissingSchemaAction = MissingSchemaAction.AddWithKey;<br />
cus_adaptr.Fill(ds, "Customer");<br />
new OleDbCommandBuilder(cus_adaptr); <br />
DataTable customer = ds.Tables["Customer"];<br />
<br />
addr_adaptr.SelectCommand = cn.CreateCommand();<br />
addr_adaptr.SelectCommand.CommandText = "Select * from Address";<br />
addr_adaptr.MissingSchemaAction = MissingSchemaAction.AddWithKey;<br />
addr_adaptr.Fill(ds, "Address");<br />
new OleDbCommandBuilder(addr_adaptr);<br />
DataTable address = ds.Tables["Address"];<br />
<br />
DataRelation cus_addr = new DataRelation("cus_addr",customer.Columns["cus_id"], address.Columns["cus_id"]); <br />
ds.Relations.Add(cus_addr);<br />
Then I defined a function to store the changes made in the dataset.
<br />
public static void save_to_database(string table)<br />
{<br />
System.Data.OleDb.OleDbDataAdapter <br />
dbAdaptr = new OleDbDataAdapter("Select * from "+table, cn);<br />
new OleDbCommandBuilder(dbAdaptr);<br />
DataTable atable = ds.Tables[table].GetChanges();<br />
int i = main_form.ds.Tables["Customer"].Rows.Count;<br />
try <br />
{<br />
dbAdaptr.Update(ds, table); <br />
} <br />
catch (Exception er)<br />
{<br />
MessageBox.Show("Cannot update invoice.mdb! " + er.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);<br />
}<br />
ds.Tables[table].AcceptChanges();<br />
}<br />
When I delete a customer record from the customer table then save it as:
save_to_database("Customer");
save_to_database("Address");
An error happens when save the address table which says:
"Concurrency Violation: the delete command affected 0 records." Does anybody know how to avoid this happen?
Also I can loop a field in address table if I delete any record, it says "can't access the deleted rows." Does anybody know how to bypass the deleted row so I still can loop the rows which are not deleted?
Thanks in advance
Asura
|
|
|
|
|
Please tell how we can give Parameters in sqladapter.
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.NVarChar, 18, "Press_job_order"));
sqlDataAdapter1.Fill(dataSet11);
where i give paramenter @Param2 value and how.
|
|
|
|
|
Couple of ways.
1) Create the param first
SqlParameter pressJobOrderParam = new SqlParameter("@Param2", SqlDbType.NVarChar, 18, "Press_job_order");<br />
pressJobOrderParam.Value = 123;<br />
this.sqlSelectCommand1.Parameters.Add(pressJobOrderParam);
2) Add the param, as you did, then refer to it by name.
this.sqlSelectCommand1.Parameters.Add(new SqlParameter("@Param2", SqlDbType.NVarChar, 18, "Press_job_order"));<br />
this.sqlSelectCommand1.Parameters["@Param2"].Value = 123;
|
|
|
|
|
Thanks for Help?
Do you have any idea about crystal report field hide and show. And date format in crystal i select date field from sql database i need to store date in dd/MMMM/yyyy format and also show in crystal report in this format. Any Idea?
....Thank again.
|
|
|
|
|
if "myDate" is of type DateTime i think to format it you use
myDate.ToString("dd/MMMM/yyyy");
|
|
|
|
|
The Add method returns a reference to the parameter, so you can set it's value.
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.NVarChar, 18, "Press_job_order")).Value = "42";
---
b { font-weight: normal; }
|
|
|
|
|
this.sqlSelectCommand1.Parameters.Add("@Param2", System.Data.SqlDbType.NVarChar, 18).Value = "Press_job_order";
or (if you're using .NET 2.0) :
this.sqlSelectCommand1.Parameters.AddWithValue("@Param2", "Press_job_order");
|
|
|
|
|
Hi,
Is it possible to use C# as a scripting language in an MFC App?
Any ideas are welcome?
thanks
Ning
|
|
|
|
|
There's an option to make it possible:
Make a COM-enabled .NET assembly with a ScriptingEngine class in it.
This class should have a method that reads a script from a .cs file and compile it dynamicly into an assembly (that is not written to disk, but kept in memory). After the method has loaded and compiled the script it should run the script.
I don't have much knowledge about passing COM objects into .NET methods, but just give it a shot and you will have something that is pretty amazing if it works.
WM.
What about weapons of mass-construction?
|
|
|
|
|
My codeis as follows For LinkButton created from the event handler lnk_Click(), I was not able to fire the event.Pls do suggest some ways to get out of it
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
LinkButton lnk3;
LinkButton lnk1;
LinkButton lnk;
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 1; i < 11; i++)
{
lnk1 = new LinkButton();
lnk = new LinkButton();
lnk.Text =Convert.ToString(i);
lnk1.Text = " ";
this.Form.Controls.Add(lnk);
lnk1.Enabled = false;
this.Form.Controls.Add(lnk1);
lnk.Click +=new EventHandler(lnk_Click);
if (i > 9)
{
lnk3 = new LinkButton();
lnk3.Text = "More";
this.Form.Controls.Add(lnk3);
lnk3.Click+=new EventHandler(lnk_Click);
}
}
}
public void lnk_Click(object sender, EventArgs e)
{
string str = ((LinkButton)sender).Text;
Response.Write("Hi Just Testing" + " "+ str);
if (((LinkButton)(sender)).Text == "More")
{
for (int i = 0; i < 11; i++)
{
lnk1 = new LinkButton();
lnk = new LinkButton();
lnk.Text = Convert.ToString(i);
lnk1.Text = " ";
this.Form.Controls.Add(lnk);
lnk1.Enabled = false;
this.Form.Controls.Add(lnk1);
lnk.Click += new EventHandler(lnk_Click);
if (i > 9)
{
lnk3 = new LinkButton();
lnk3.Text = "More";
this.Form.Controls.Add(lnk3);
lnk3.Click += new EventHandler(lnk_Click);
}
}
}
}
}
|
|
|
|
|
i've to set some conditions to my program. user has to enter a string of 2 letters + 7 numbers in this order eg. x1234567y
how do i set the conditions to make sure the order is correct?
thanks
|
|
|
|
|
use regular expression
MCAD
|
|
|
|
|
what do u mean by regular expression? i was told to do onkeypress event on textbox.. how do i start doing that, do u know?
|
|
|
|