|
|
I was using vs2005. In this how can I built
|
|
|
|
|
|
i am working with mutiple forms, i want to update the DataGridView of form2 in form3,DAtaGridView gets the table from the data base, i want to update the DataGridView which is in Form2. but cant update it from Form3.DataGridView is not accessable in Form3.
plzzzzzzzzzz help me out.
thanx in advance.
|
|
|
|
|
I am a little confused as too what you want to do, so check if this is correct.
You have two forms:
a) form2 which contains a DataGridView that gets the table from a database.
b) form3 which does some other procesing and wants to supply information to the DataGridView of form2.
c) form3 cannot access the DataGridView of form2.
If this is the case, then it is bad practice to access such members of form2, as it means that form3 becomes reliant on the internal structure of form2. A change to form2 requires a change in form3, which means that form3 cannot be reused easily.
The better way to do this is for form3 to signal an event to form2 ("Update ready" or similar) and provide any necessary data via a queue in form3, or via the event argument.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
modified on Wednesday, August 12, 2009 6:12 AM
|
|
|
|
|
Hi
i created a web service with two method that will be call via sharepoint bdc. my problem is that adf file was successfully imported but it has a warning :
Application definition was successfully imported. 1 warning(s) found. Consider fixing the warnings and updating the application definition.
Warning :
Could not create profile page for Entity News. The error is: Profile page creation for the Entity News skipped. Entity News has no identifiers defined in the SpecificFinder view
Here is my web service :
[WebMethod]
public List<News> GetNews()
{
List<News> list = new List<News>();
using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ConnectionString))
{
using (MySqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "select id,title,introText,created from jos_content order by created desc,id desc";
if (con.State != System.Data.ConnectionState.Open)
con.Open();
MySqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
list.Add(new News(dr.GetInt32(0), dr.GetString(1), dr.GetString(2), dr.GetString(3)));
}
dr.Close();
if (con.State != System.Data.ConnectionState.Closed)
con.Close();
}
}
return list;
}
[WebMethod]
public List<News> GetNewsByID(int id)
{
List<News> list = new List<News>();
using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ConnectionString))
{
using (MySqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "select id,title,introText,created from jos_content where id=@id order by created desc,id desc";
cmd.Parameters.Add(new MySqlParameter("@id", id));
if (con.State != System.Data.ConnectionState.Open)
con.Open();
MySqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
list.Add(new News(dr.GetInt32(0), dr.GetString(1), dr.GetString(2), dr.GetString(3)));
}
dr.Close();
if (con.State != System.Data.ConnectionState.Closed)
con.Close();
}
}
return list;
}
here is my News class :
public class News
{
int _newsID;
string _newsTitle;
string _newsBody;
string _dateCreated;
public string DateCreated
{
get { return _dateCreated; }
set { _dateCreated = value; }
}
public int NewsID
{
get { return _newsID; }
set { _newsID = value; }
}
public string NewsTitle
{
get { return _newsTitle; }
set { _newsTitle = value; }
}
public string NewsBody
{
get { return _newsBody; }
set { _newsBody = value; }
}
public News()
{
}
public News(int id, string title, string body, string dateCreated)
{
this.NewsID = id;
this.NewsTitle = title;
this.NewsBody = body;
this._dateCreated = dateCreated;
}
}
here is my adf file :
<LobSystemInstances>
<LobSystemInstance Name="ServiceInstance">
<Properties>
<Property Name="LobSystemName" Type="System.String">Service</Property>
</Properties>
</LobSystemInstance>
</LobSystemInstances>
<Entities>
<Entity Name="News">
<Properties>
<Property Name="NewsTitle" Type="System.String">NewsTitle</Property>
</Properties>
<Identifiers>
<Identifier Name="NewsID" TypeName="System.Int32"></Identifier>
</Identifiers>
<Methods>
<Method Name="GetNews">
<Parameters>
<Parameter Direction="Return" Name="GetNewsResults">
<TypeDescriptor TypeName="ServiceProxy.News[],Service" IsCollection="true" Name="ArrayOfNews">
<TypeDescriptors>
<TypeDescriptor TypeName="ServiceProxy.News,Service" Name="News">
<TypeDescriptors>
<TypeDescriptor TypeName="System.Int32" IdentifierName="NewsID" Name="NewsID" />
<TypeDescriptor TypeName="System.String" Name="NewsTitle" />
<TypeDescriptor TypeName="System.String" Name="NewsBody" />
<TypeDescriptor TypeName="System.String" Name="DateCreated" />
</TypeDescriptors>
</TypeDescriptor>
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Name="FinderGetNewsResultsInstance" Type="Finder" ReturnParameterName="GetNewsResults" ReturnTypeDescriptorName="ArrayOfNews" ReturnTypeDescriptorLevel="0" />
</MethodInstances>
</Method>
<Method Name="GetNewsByID">
<FilterDescriptors>
<FilterDescriptor Type="Comparison" Name="NewsID" />
</FilterDescriptors>
<Parameters>
<Parameter Direction="In" Name="NewsID">
<TypeDescriptor TypeName="System.Int32" Name="NewsID" AssociatedFilter="NewsID" IdentifierName="NewsID" />
</Parameter>
<Parameter Direction="Return" Name="GetNewsByIDResults">
<TypeDescriptor TypeName="ServiceProxy.News[],Service" IsCollection="true" Name="ArrayOfNews">
<TypeDescriptors>
<TypeDescriptor TypeName="ServiceProxy.News,Service" Name="News" IdentifierName="NewsID">
<TypeDescriptors>
<TypeDescriptor TypeName="System.Int32" Name="NewsID" />
<TypeDescriptor TypeName="System.String" Name="NewsTitle" />
<TypeDescriptor TypeName="System.String" Name="NewsBody" />
<TypeDescriptor TypeName="System.String" Name="DateCreated" />
</TypeDescriptors>
</TypeDescriptor>
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Name="SpecificFinderGetNewsByIDResultsInstance" Type="SpecificFinder" ReturnParameterName="GetNewsByIDResults" ReturnTypeDescriptorName="ArrayOfNews" ReturnTypeDescriptorLevel="0" />
</MethodInstances>
</Method>
</Methods>
</Entity>
</Entities>
where is my problem and how to solve it ?
thanks
|
|
|
|
|
Hi,
I am making an application integrated with Microsoft Project 2003 in c#. Now ,I want to convert .MPP file in .xml file using C#. I don't how to do this. I need help books or reference guide for integrating with Microsoft Project In C#. if you have any idea .please let me know immediately.
Thanks in advance
Regards,
Rajesh
rajesh
|
|
|
|
|
Hi,
were you able to convert it? since i am having the same problem
Thanks
|
|
|
|
|
Hi !! Have a good day
I have a question, please help me !
I want to split a datatable into many datatables, how to do that by c#.net.
Example : datatable is: DA has 250 rows ==> split into 3 datatable : DA1 (100rows) , DA2(100 rows), DA3(50rows)
If datatable DA has 1000 rows, ==> split into 10 datatables, ( thats mean one datatable have less than 100rows)
Thanks for your help!
|
|
|
|
|
You will have to loop through the rows and copy them into a new datatable. You can also use DataTable.Select method as well instead of looping through all the rows.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
The simplest way would be to write a loop that iterated over the DataTable and allocate rows accordingly. When you do this, you need to clone the table structure, and use ImportRow to copy the row from one table to another. If you attempt to copy the row over directly, you'll get a "row belongs to another table" error. The following method does what you want:
private List<DataTable> CloneTable(DataTable tableToClone, int countLimit)
{
List<DataTable> tables = new List<DataTable>();
int count = 0;
DataTable copyTable = null;
foreach (DataRow dr in tableToClone.Rows)
{
if ((count++ % countLimit) == 0)
{
copyTable = new DataTable();
copyTable = tableToClone.Clone();
tables.Add(copyTable);
}
copyTable.ImportRow(dr);
}
return tables;
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks for your method !
But i have little experience in c#. can you explain me what is List<datatable>, how can i define ?
I'm writing in c#.net 2003
|
|
|
|
|
This code working fine..Thanks lot
|
|
|
|
|
I will try to shorten this question. If I have the following class:
public class MyClass
{
public int MyInt {get; set;}
public Button MyBtn {get; set;}
}
Now, let's say I have a for-loop that generates several objects of this class and hooks it up to an event handler like this:
for (int i = 0; i < 5; i++)
{
MyClass myClass = new MyClass();
myClass.MyInt = i;
myClass.MyBtn = new Button();
myClass.MyBtn.Click += (s, e) =>
{
};
}
So, my question is: Is it possible to get the value of 'myClass.MyInt' when the button is clicked? I mean, 'myClass.MyBtn' and 'myClass.MyInt' belongs to the same object. The problem is that I must hook up all buttons to the same event handler.
Thanks for help!
|
|
|
|
|
If you look at the method declaration for your event handler, you'll see a parameter called s of type object - by convention, this is the object that raised the event. So, all you need do is cast s to Button as in:
Button button = s as Button;
if (button != null)
{
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks for the reply.
Yes, I know I can get the object that raised that event. But that object belongs to an object 'myClass' which in turn contains 'myClass.MyInt'. Is it possible to get which of the 'myClass.MyBtn' that raised the event. If I can get that I would also be able to read out the value of 'myClass.MyInt'
|
|
|
|
|
Yes. There are 5 MyClass instances and you can use one method for all events. This is better :
private List<MyButton> myButtons = new List<MyButton>();
private void CreateButtons()
{
for(int i = 0; i < 5; i++)
{
MyButton myButton = new MyButton();
myButton.MyInt = i;
myButton.Click += new EventHandler(myButton_Click);
myButtons.Add(myButton);
}
}
private void myButton_Click(object sender, EventArgs e)
{
MyButton myButton = sender as MyButton;
if(myButton != null)
{
MessageBox.Show(myButton.MyInt.ToString());
}
}
public class MyButton : Button
{
private int myInt;
public int MyInt
{
get { return myInt; }
set { myInt = value; }
}
}
|
|
|
|
|
Thanks for the reply!
I think that was exactly what I was looking for. I'll try to implement this in my real case and I get back if I don't succeed.
|
|
|
|
|
You don't even need an extra class, you could store the MyClass reference inside the Button using myClass.MyBtn.Tag=myClass; so later an event handler could convert its sender to Button to MyClass instance.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
xkrja wrote: //Is it possible to get the value of 'myClass.MyInt'
//in this event handler since 'myClass.MyBtn' belongs
//to the same object?
In your example code: yes.
Just use myClass.MyInt . The lambda expression will capture the myClass variable, so every event handler will know to which MyClass instance it belongs.
You should not capture the i variable - that would always be 5 because the loop has terminated when the event executes.
But capturing variables declared inside the loop will give you the value from the corresponding iteration.
|
|
|
|
|
how do i insert a new line character.
i want to display a sentence in next line. i selected the multiline property. i want to display the second line in next line of text box like wise \n in C lang
can any one help pls
This code was posted by me...
|
|
|
|
|
|
Just add "\r\n" to the end of your line and the next text will be on the next line.
textbox1.text = string.format("{0}\r\n{1}","this is on line 1","this is on line 2");
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Environment.NewLine will do that.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hi all.
I made an application for communicating with serial port.
But there is a trouble.
In the DataReceived event when I wanna fill textbox with data that given from serial port an Exception has occurred.
http://www.picfront.org/d/bV1xDokvV/u.png[^]
Could you please guide me how I can resolve it ?
|
|
|
|