|
Hi!
I can't seem to make it work. I select a row in a datagrid and press a delete button. That row is then deleted. But if i add/delete many rows, then close and reopen my dialog and try to delete a row again, the row with index 0 is deleted instead of the one i have selected. I have tried to use currency manager to delete and everything, but I can't make it work properly.
This is how I delete a row:
<br />
if(_currencyManager.Current.GetType() != typeof(DataRowView)) return;<br />
<br />
DataRowView dr = (DataRowView)_currencyManager.Current; <br />
dr.Delete(); <br />
_currencyManager.EndCurrentEdit();<br />
_currencyManager.Refresh(); <br />
_dtPplan.AcceptChanges();<br />
I set the currency manager like this:
<br />
_currencyManager = (CurrencyManager)this.BindingContext[dgPplan.DataSource, dgPplan.DataMember];
And fill the table with data like this each time i open the dialog. Just so i'm sure it got the latest data:
<br />
_dtPplan.Rows.Clear();<br />
foreach(PPlan pPlan in valueObject.PPlan) <br />
{ <br />
DataRow dr = _dtPplan.NewRow();<br />
dr[NetworkKeywords._cCriteria] = pPlan.Criteria;<br />
dr[NetworkKeywords._cParameter] = pPlan.Parameter;<br />
dr[NetworkKeywords._cValue] = pPlan.Value;<br />
dr[NetworkKeywords._cUnit] = pPlan.Unit;<br />
_dtPplan.Rows.Add(dr);<br />
}<br />
_dtPplan.AcceptChanges();<br />
<br />
_currencyManager = (CurrencyManager)this.BindingContext[dgPplan.DataSource, dgPplan.DataMember]; <br />
I really need help on this. This datagrid/datatable is driving me crazy.
Thanks in andvance
Atle
|
|
|
|
|
I would suggest you that,instead of having a delete button, u keep a contextmenu for the datagrid, and in the delete menu click event,u delete the selected row..sumthin like this..
int rowIndex = dataGrid1.CurrentRowIndex;
dataTable.Rows[dataGrid1.CurrentRowIndex ].Delete();
//then call the function to delete the row
and u retrieve the data correctly
try it..datagrids n datatables ain't so bad
|
|
|
|
|
I also have an "Add" and "Delete All" button that I need. The way you are mentioning her will work with a button too won't it? Just use your code inside the buttons aciton?
What happens when I sort the datagrid? Then the row indexes in the datagrid won't correspond to the row indexes in the datatable will they? Only the datagrid's rows are sorted, or? Then I will need the currency manager to keep track of that?
- Atle
|
|
|
|
|
I agree with deep7.
You can have a context menu with the following items
Delete,
Delete All
You can add a new row on mouse click on the white region.
private void OnGridMouseUp(object sender, MouseEventArgs e)
{
//Get Current Point
this.hitTestGridInfo = this.dataGridAllocation.HitTest(new Point(e.X, e.Y));
//Capture Grid Body Event
if (this.hitTestGridInfo.Type == DataGridEx.HitTestType.None &&
e.Button == MouseButtons.Left )
{
newDataRow = this.dataTable.NewRow();
this.dataTable.Rows.Add(newDataRow);
}
}
As far as sort order is concerned, you can use,
private DataRow GetDataRowAt(int index)
{
DataRow dataRow = null;
CurrencyManager currencyManager = null;
currencyManager = (CurrencyManager)this.BindingContext[this.dataTable];
if ( currencyManager != null )
{
dataRow = ((DataRowView)currencyManager.List[index]).Row;
}
return dataRow;
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
Looks like the datagrid is messed up after refilling the datatable or something. You see how i fill it with data in my first post. Is there another way to do it? I need to fill in some data from an arraylist. I refill the datagrid according to what I select in a combobox.
It seems my problem is that after clearing and refilling the datatable with data a couple of times (selecting differend things in the combobox), the datagrid returns selected row index = 0 for each and every row i press. Then suddenly it can return index out of bounds exception when I press a row??
- Atle
|
|
|
|
|
Hmm....seems like it likes
<br />
foreach(DataRow row in _dtPplan.Rows) <br />
{<br />
row.Delete();<br />
}<br />
_dtPplan.AcceptChanges();<br />
for deleting all rows than
<br />
_dtPplan.Rows.Clear()<br />
I have to test it a little more, but it seems like the index problem is gone now. It works with the add and delete buttons in the form by the way. Thanks for your help.
- Atle
|
|
|
|
|
hi all,
I need to shedule a Task in windows 2000.I can easily do it using Control Panel--->Sheduled Task ..
But How am I shedule a task using a C# Application..?
Can any one please help me.?
thanks in advance..
|
|
|
|
|
|
I'm using
System.IO.Directory.GetCreationTime(folderName)
to get the creation date of a folder, but it throws an ArgumentOutOfRangeException with the message
"Specified argument was out of the range of valid values.
Parameter name: Not a valid Win32 FileTime."
The folder in question is on a CDR that was burnt on a PC with a different datetime locale. Why is it that Windows Explorer can display the datetime of the folder without any problems, but the .net framework chokes on it? Does System.IO.Directory require some sort of CultureInfo to parse dates? If so, where do I specify this?
Thanks in advance
|
|
|
|
|
I am trying to limit the amount of time an ASP.NET Web Service can spend processing a client’s request.
Currently if the client sets it’s timeout to Infinite the server will allow the request to complete; however I want to stop the request and send a custom response back to the client after a specified time limit.
What is the best way of achieving this?
|
|
|
|
|
How can i get the hard disk Id or the motherboard ID programatically?
hosny
|
|
|
|
|
|
hi all,
in my code i'm populating a combobox which is one of the columns in th datagrid.
i want the combobox to be populated with data from two tables from the database.
like for example the 'name' and the 'Description'.
At present i'm getting only the 'name in the combobox.
how to get its description also ??
|
|
|
|
|
did you mean by using data binding or by the code
if you mean data binding i think you can not
bind combo box to two fields
in the code get the data and loop for each recored add the two fields value
|
|
|
|
|
i'm getting only the names in the combobox, but i also want the description to be next to the name separated by space.
m doing it as below...
newColumnStyle.MappingName = "New";
newColumnStyle.HeaderText= "New";
newColumnStyle.Width = 101;
newColumnStyle.MyComboBox.Items.Clear();
for(int i = 0; i < getData.Length; i++)
newColumnStyle.MyComboBox.Items.Add(getData[i].name );//here how to add in the combobox the 'getData[i].description'
tableStyle.GridColumnStyles.Add(newColumnStyle);
any help appreciated
|
|
|
|
|
try somthing like this
newColumnStyle.MyComboBox.Items.Add(getData[i].name + " " + getData[i].description)
|
|
|
|
|
thanx...silly me dinn think of concating...
but my problem ain't solved yet.
when i select one of the names, and then i fill in other columns other details, and click on 'save' button, only the name should be saved and not the description...
in save button click,
for each row,
for (int i = 0; i < dataTable.Rows.Count ;i++)
{
testData.name = Convert.ToString(dataGrid1[i ,2]).Trim();
//other details from the datagrid
//then i call a function to add the details from the datagrid in the database
addDetails(testData);
}
thanx for helping
|
|
|
|
|
you need to extract name only
some thing like the following will extract it
//text that contain both name and description
//" " the sperator replace it with your own
<br />
string name=text.Substring(1,text.IndexOf(" ")+1);
then testData.name=name
|
|
|
|
|
thank u
|
|
|
|
|
HI All, I want to write a "Send To" menu class using C#(it's function just link the "Send To" Menu in the windows OS,send files to a specified target,such as desktop,MyDocument,Mail Recipient etc.), and I've finished it ,but there is still some problems .I use COM code (use IShellFolder,IDropTarget etc.) to do this work, this is too complex I think, so I want to know are there any simple ways to do it?
Can we use command line to do it?
|
|
|
|
|
lin1161 wrote:
I use COM code (use IShellFolder,IDropTarget etc.) to do this work, this is too complex I think, so I want to know are there any simple ways to do it?
Can we use command line to do it?
How would you expect your command line code to make it into the shell ? The shell uses COM, you need to use COM to interface with it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If we can't use command line to do it , are there any other simple ways to do it?
|
|
|
|
|
As has been pointed out, there are no simpler ways than using the COM interfaces.
Sorry, you have to live with it.
Regards,
mav
|
|
|
|
|
|
Why ? He's already written it, he's saying it's too complex. This project does the exact same thing he has done, using the same COM interfaces.
Christian Graus - Microsoft MVP - C++
|
|
|
|