|
I am storing an object in one of the cell's tag in my dataGridView. As soon as I click on one of the column headings (to sort the grid) the object stored in the tag is deleted (tag is null). I have not overridden the sort functionality for the grid, it is just the default sort. Any ideas as to why the object stored in the tag is being deleted/nulled out? My data grid does have a binding source/datasource so not sure if that has anything to do with it.
Any help/ideas would be appreciated
Thanks!
|
|
|
|
|
hi
i want to get customers data from database as CustomerCollection class (strongly typed), and bind my dataGridView to my CustomerCollection object.
i defined Customer class as follow :
class Customer<br />
{<br />
private string customerID;<br />
private string companyName;<br />
<br />
public string CustomerID<br />
{<br />
get { return customerID; }<br />
set { customerID = value; }<br />
} <br />
<br />
public string CompanyName<br />
{<br />
get { return companyName; }<br />
set { companyName = value; }<br />
}<br />
<br />
public Customer() { }<br />
<br />
public Customer(string custID, string company)<br />
{<br />
this.CustomerID = custID;<br />
this.CompanyName = company;<br />
}<br />
<br />
public DataTable GetCustomers()<br />
{<br />
DataAccess da = new DataAccess("Data Source=.;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=1");<br />
DataTable dt = new DataTable();<br />
da.ExecuteCommand(new SqlCommand("SELECT CustomerID,CompanyName FROM CUSTOMERS"),out dt); <br />
return dt;<br />
} <br />
}
and defined CustomerCollection class as follow :
class CustomerCollection : System.Collections.CollectionBase<br />
{<br />
public CustomerCollection()<br />
{<br />
<br />
}<br />
<br />
public void Add(Customer customer)<br />
{<br />
List.Add(customer);<br />
}<br />
<br />
public void Remove(Customer customer)<br />
{<br />
List.Remove(customer);<br />
}<br />
<br />
public Customer this[int index]<br />
{<br />
get<br />
{<br />
return (Customer)List[index];<br />
}<br />
<br />
set<br />
{<br />
base.List[index] = value;<br />
}<br />
}<br />
}
but i don't know when i use this code :
Customer c = new Customer();<br />
this.dataGridView1.DataSource = c.GetCustomers();
how to bind my datagridView to my strongly typed collection object (CustomerCollection), how to do ?
thanks
|
|
|
|
|
Well, have you considered calling DataBind? That'll do it.
|
|
|
|
|
thanks for reply
when i use this code :
Customer c = new Customer();<br />
this.dataGridView1.DataSource = (CustomerCollection)c.GetCustomers();
the following error has shown me :
Cannot convert type 'System.Data.DataTable' to '_LayerSample.CustomerCollection'
|
|
|
|
|
Don't return a DataTable from your GetCustomers method. You need to return your List<customercollection> so you can databind to that.
So you need to change your GetCustomers to fetch the data from the database and use a datareader. iterate the datareader and create a new Customer class for each dataitem in the reader and fill the appropriate properties. Before your next iteration, add that Customer class to the collection with your Add method. Rinse and Repeat.
|
|
|
|
|
So you need to change your GetCustomers to fetch the data from the database and use a datareader. iterate the datareader and create a new Customer class for each dataitem in the reader and fill the appropriate properties. Before your next iteration, add that Customer class to the collection with your Add method. Rinse and Repeat.
thanks for reply
i know this way to get data strongly typed, is there any other way to get data strongly typed ?
however many thanks
regards.
|
|
|
|
|
I have an SqlConnection, what i need is to get the server value and the database value from the connectionstring it contains.
Is there an easy way to get these values, or do I have to resort to using the dreadful regexp?
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
|
|
|
|
|
Nvm, solved it ^^
SqlConnectionStringBuilder connstr = new SqlConnectionStringBuilder(ConnectionString);
string server = (string) connstr["server"];
string database = (string)connstr["database"];
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
|
|
|
|
|
Dear All,
I am a novice c# programmer, I am astounding seeing following code block
<br />
<br />
public class NewClass<br />
{<br />
public static NewClass Add(parm1,parm2)<br />
{<br />
NewClass newclass = new NewClass();<br />
return newclass; <br />
}<br />
}<br />
<br />
<br />
I want to what logic behind this return type(as class)
What it actually returns? what type is this, I am unware of this.. Any help highly accepted.
|
|
|
|
|
You need to buy a beginners book and work through it for the basics.
You can return any type you like, including types you define.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Can we use the DataAdapter method like
if(dAdapter.Upadate(dt) == 1)
MessageBox.Show("Update successful");
->Is Update method alwaya return 1 on successful update ?
->Is this is correct way to use the information that data has been updated?
-> If no, then what can be the possible consequencies ?
Your comments are welcome
|
|
|
|
|
Gee golly gosh, they do have a habbit of hiding this stuff in the documentation[^]
[quote]
Return Value
Type: System..::.Int32
The number of rows successfully updated from the DataTable.
[/quote]
|
|
|
|
|
Hello,
I am searching for a professional windows forms thumbnail component that will display images with the look and feel of the Windows Vista pictures folders or something similar.
Searching on the net I found many asp.net thumbnail components but nothing for windows forms.
Do you now any?
Thanks
|
|
|
|
|
can someone help me with how to calculate the variance and gradient of pixels contained in an image.
tony-yeyo
|
|
|
|
|
I guess you just want to access the pixels, as per my image processing articles, then build a list of how often each value occurs ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Ive got a legacy Windows Form Application (framework 1.1).Initally it was built for one person but two more people would like to use it at their desktop. I dont want to install it on there desktop how do i go about sharing his application from one remote location.
|
|
|
|
|
1. Run from a shared folder, remember to setup the trusting of assemblies.
2. Use ClickOnce to deploy to them. (VS2005 only)
By the way, your application handles concurrency, right?
|
|
|
|
|
Yes it does. Thanks Dude!!
|
|
|
|
|
Hello everyone.
I have a little application which accepts an excel file, performs a formal check on it (nothing special, it just tries to see if there's a number or a string where they should be) and then inserts the records in a database.
This application loads the excel file, puts all the data in a datatable, then performs the formal check.
To do so, I use an instance of OleDbDataAdapter and call the Fill(table) method to fill up a table.
What is startling me the most is that with some Excel files, if I erase the last row manually (e.g. in MSExcel, clicking in the cells and pressing DEL), the row is not completely erased, so the datatable resulting from the Fill() operation has one last row empty, which is causing the formal check to fail - thus preventing the file to be loaded, since it works in an all-or-nothing basis (one rows fail, the whole file is discarded).
The thing that is driving my crazy is that this happens only on SOME excel files! Even using the same Excel installation on the very same machine, some files will show this behaviour, some others won't.
Has anything similar ever happened to some of you? I cannot really get a grasp of this.
Thanks in advance
Rey9999
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
Hi, this reminds me of the many problems i've experienced with sql server DTS using excel files as the source. The solution is to ensure there are no blank lines at the bottom of your dataset in the spreadsheet (use Ctrl-End in excel to see if there are any blank lines). you can do this by copying the data to a new worksheet before running your app. Alternatively, you could check each row for blanks as you populate the dataTable.
Rob
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
Thank you.
Indeed, I solved the issue with a "dirty trick": after I've populated the DataTable, I check the last row and erase it if it's blank (I do not need to check them all, because the excel files they give me never have blank lines in between, apart from the last one - and that was actually causing the problem amongst my program's users)
Thanks again!
Rey9999
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
Hi all,
How can I make use of the SortedListand the Control within the foreach loop below:
When I try I get the following exception:
Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'System.Windows.Forms.Control'.
SortedList sorted = new SortedList();
for (int c = (xPPanelAddStock.Controls.Count - 1); c > 0; c--)
{
sorted.Add(xPPanelAddStock.Controls[c].Name, xPPanelAddStock.Controls[c]);
}
foreach (Control stockAddControl in sorted) EXCEPTION OCCURS
{
...
Can anyone please help.
Many thanks
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
|
|
Hey, me again
You can also do this if you need access to the key value as well:
SortedList<String, Control> myList = new SortedList<string, Control>();
foreach (KeyValuePair<String, Control> pair in myList)
{
String thisIsTheString = pair.Key;
Control thisIsTheControl = pair.Value;
}
Simon
|
|
|
|