|
Hey, thanx for the reply...
that was the logical sollution for me too, but it doesnt allow the 2nd index (the one for the column)
i tried these and they did not work
foreach (DataGridViewRow row in pollTimesDataGridView)
{
string myString = row[0];
MessageBox.Show(myString);
}
for (int i = 0; i < pollTimesDataGridView.Rows.Count; i++)
{
MessageBox.Show(pollTimesDataGridView.Rows[i][0]);
}
any ideas?
thanx justin
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi,
Here is the code for foreach
DataGridView grvCompany = new ....;
foreach (DataGridViewRow row in grvCompany.Rows)
{
//
}
Thanks!
Charith
jayasshc
|
|
|
|
|
Run code, press down arrow, up arrow, down arrow.
Invalid operatoin exception occurs.
How to fix ?
Andrus.
using System;<br />
using System.Windows.Forms;<br />
using System.ComponentModel;<br />
<br />
class Supplier {<br />
public string Id { get; set; }<br />
}<br />
<br />
class Form1 : Form {<br />
[STAThread]<br />
static void Main() {<br />
Application.Run(new Form1());<br />
}<br />
<br />
public Form1() {<br />
DataGridView grid = new DataGridView();<br />
grid.EditMode = DataGridViewEditMode.EditOnEnter;<br />
ComboBoxColumn comboBoxColumn = new ComboBoxColumn();<br />
ComboBoxCell ComboBoxCell = new ComboBoxCell();<br />
comboBoxColumn.CellTemplate = ComboBoxCell;<br />
grid.Columns.Add(comboBoxColumn);<br />
BindingList<Supplier> l = new BindingList<Supplier>();<br />
l.Add(new Supplier());<br />
grid.DataSource = l;<br />
Controls.Add(grid);<br />
}<br />
<br />
class ComboBoxColumn : DataGridViewComboBoxColumn { }<br />
<br />
class ComboBoxCell : DataGridViewComboBoxCell {<br />
public override Type EditType {<br />
get {<br />
return typeof(ComboBoxEditingControl);<br />
}<br />
}<br />
<br />
}<br />
<br />
class ComboBoxEditingControl : ComboBox, IDataGridViewEditingControl {<br />
protected int rowIndex;<br />
protected DataGridView dataGridView;<br />
protected bool valueChanged = false;<br />
<br />
protected override void OnTextChanged(EventArgs e) {<br />
base.OnTextChanged(e);<br />
NotifyDataGridViewOfValueChange();<br />
}<br />
<br />
protected virtual void NotifyDataGridViewOfValueChange() {<br />
valueChanged = true;<br />
if (dataGridView != null) {<br />
dataGridView.NotifyCurrentCellDirty(true);<br />
}<br />
}<br />
<br />
public Cursor EditingPanelCursor {<br />
get {<br />
return Cursors.IBeam;<br />
}<br />
}<br />
<br />
public DataGridView EditingControlDataGridView {<br />
get {<br />
return dataGridView;<br />
}<br />
set {<br />
dataGridView = value;<br />
}<br />
}<br />
<br />
public object EditingControlFormattedValue {<br />
set {<br />
if (value.ToString() != Text) {<br />
Text = value.ToString();<br />
NotifyDataGridViewOfValueChange();<br />
}<br />
}<br />
<br />
get {<br />
return Text;<br />
}<br />
}<br />
<br />
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts<br />
context) {<br />
return Text;<br />
}<br />
<br />
<br />
<br />
public void PrepareEditingControlForEdit(bool selectAll) { }<br />
<br />
public bool RepositionEditingControlOnValueChange {<br />
get {<br />
return false;<br />
}<br />
}<br />
<br />
public int EditingControlRowIndex {<br />
get {<br />
return rowIndex;<br />
}<br />
<br />
set {<br />
rowIndex = value;<br />
}<br />
}<br />
<br />
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle<br />
dataGridViewCellStyle) {<br />
DropDownStyle = ComboBoxStyle.DropDown;<br />
}<br />
<br />
public bool EditingControlWantsInputKey(Keys keyData, bool<br />
dataGridViewWantsInputKey) {<br />
return !dataGridViewWantsInputKey;<br />
}<br />
<br />
public bool EditingControlValueChanged {<br />
<br />
get {<br />
return valueChanged;<br />
}<br />
set {<br />
valueChanged = value;<br />
}<br />
}<br />
}<br />
}
Andrus
|
|
|
|
|
If I was you, I'd think it would be easiest to get help if I posted the entire, actual error message, and only the little relevant piece of code. Otherwise, we have to guess where the error is coming from, and what it is, because no one is going to read through all that code to find where it is coming from.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
Justin,
thank you.
Exception occurs in Application.Run() method:
System.InvalidOperationException was unhandled
Message="Operation is not valid due to the current state of the object."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at System.ComponentModel.BindingList`1.AddNewCore()
at System.ComponentModel.BindingList`1.System.ComponentModel.IBindingList.AddNew()
at System.Windows.Forms.CurrencyManager.AddNew()
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew()
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded()
at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.ProcessDownKeyInternal(Keys keyData, Boolean& moved)
at System.Windows.Forms.DataGridView.ProcessDownKey(Keys keyData)
at System.Windows.Forms.DataGridView.ProcessDataGridViewKey(KeyEventArgs e)
at System.Windows.Forms.DataGridView.ProcessKeyPreview(Message& m)
...
This is probably caused because DataGridView does not call RemoveItem() event when it cancels edit.
You can run this code to see it.
Andrus.
Andrus
|
|
|
|
|
I am a junior software engineer..am getting so much of doubts on sql server 2000.Tell you..please solve my issue to work with it better.
Ok the matter is ,how can i insert a lot of strings in the same time to the same field ?.
for example..I want to insert 'xp','vista','mac' and a hundreds of other names again.
So how can i add those hundreds of strings with one querry.
and it should go to one and same field
help me please...
|
|
|
|
|
|
HI,
I need to append new tags to the existing xml document.
PLease review this code ,
string txt = TextBox1.Text.ToString();
XmlDocument doc= new XmlDocument();
doc.LoadXml(txt);
XmlElement el = doc.CreateElement("property1");
el.SetAttribute("name1", "C1");
el.InnerText = "This row is being appended to the end of the document.";
doc.DocumentElement.AppendChild(el);
doc.Save(txt);
This code will be helpful to create the childnode, but iam looking for appending Root node as well as childnodes.
Please help me to extend this code for Root nodes.
Note : no need to create XmlDeclaration statement becoz it will be thr for selected xml file by default.
Appreciate your precious reply.
Thanks a lot,
Anjali...
|
|
|
|
|
mayuri123 wrote: but iam looking for appending Root node
XmlElement eRoot = doc.CreateElement("Root");<br />
doc.AppendChild( eRoot);
Keep in mind you can only have one root element
led mike
|
|
|
|
|
led mike wrote: Keep in mind you can only have one root element
Only if you want it to be valid
only two letters away from being an asset
|
|
|
|
|
Hi all,
String.replace("\","\\") never work for me.I am also try use char,but still no work. Can anyone help me on this?
regards
cocoon
|
|
|
|
|
Does this work?
String.replace("\\","\\\\")
|
|
|
|
|
The backslash in a string is used as an escape character and won't get printed on its own. To print a backslash, the string would be "\\". Another example of common usage of \ would be "\n" to perform a new line.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
String.replace(@"\",@"\\")
SkyWalker
|
|
|
|
|
Hi ,
Thanks for fast reply. Yes, string.replace("\\","\\\\") and string.replace(@"\",@"\\") are work great,thanks guy!
|
|
|
|
|
Hi,
i am currently taking part in a project at my university and making my first advanced steps in programming in C# and .NET. In my group we want to implement a sound module to manipulate the mic input. Due to our low level of experience we have several problems. Currently we can just load a wav-File into a buffer, adding a custom sample effect und play it back, all using DirectSound.
In theory, we want to be able to load the continous microphone input into a buffer to manipulate it in "real time" and then give the modified stream out of the buffer back through the speaker. I am sure there will always be a short delay, put hopefully it can not be recognized.
Most of the audio examples cover a recording of a mircrophone input into a wav-File. My intention is not to ask for the implementation of our project, but I hope you can give us some hints how we should begin and which functions are essential for our functionality.
We currently use C# with the latest .NET Framework (3.5) and DirectSound.
I am looking forward to a good excited discussion.
Sincerly,
Daniel
|
|
|
|
|
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.
|
|
|
|