I have a grid control with unbound columns in it.
The question is, everytime I change a cell value (I am using a repository item) I immediately call the gridview.PostEditor() method so that it would right away update the grid data which requires to be updated everytime I change a specific cell. Keep in mind that I am using the PostEditor() method so that I dont have to lose the focus on a cell first to update the gridview. Anyway, calling the PostEditor() will update my grid (which works fine) and still have the reposiroty item open, a repositoty item spin edit control to be exact, but the thing is if I hit a numeric key, It will discard the old value and replace it with the new one. I don't want it to behave like this. I want it so if the old value is 10.00 and I press the "0" key it will change the value to a "100.00" not back to "0.00".
Please help!
Thanks! :)
I dont know if I understand the question. But I did a search on some of my personal devexpress stuff and found this:
private void riSpinEdit_EditValueChanged(object sender, EventArgs e)
{
TextEdit edit = grdReceiveGoods.FocusedView.ActiveEditor as TextEdit;
if (edit != null)
{
int len = edit.SelectionLength;
int start = edit.SelectionStart;
grdReceiveGoods.FocusedView.PostEditor();
edit.SelectionLength = len;
edit.SelectionStart = start;
}
}
Let me know if this solves your problem.
Related
I have tried to get an answer to this but so far no help has been able to do what I want it to.
I have this piece of code, which is meant to look at the selected row and output it's columns into the corresponding text boxes.
private void DataGridView01_SelectionChanged(object sender, EventArgs e)
{
if (DataGridView01.SelectedRows.Count > 0)
{
personIDTextBox.Text = DataGridView01.SelectedRows[0].Cells[0].Value.ToString();
comboBox1.Text = DataGridView01.SelectedRows[0].Cells[1].Value.ToString();
Txt_FirstName.Text = DataGridView01.SelectedRows[0].Cells[2].Value.ToString();
mIDDLENAMETextBox.Text = DataGridView01.SelectedRows[0].Cells[3].Value.ToString();
sURNAMETextBox.Text = DataGridView01.SelectedRows[0].Cells[4].Value.ToString();
cITYTextBox.Text = DataGridView01.SelectedRows[0].Cells[5].Value.ToString();
eMAILTextBox.Text = DataGridView01.SelectedRows[0].Cells[6].Value.ToString();
}
}
When I launch the program, I get no errors but it doesn't output the data into the textbox. Anyone know what I am doing wrong?
HOOKING UP EVENTS:
It is the most basic thing you need to learn to code in VS. In short it means that the event name, here DataGridView01_SelectionChanged is connected to the event. To do so one can either use code or one inserts it into the correct slot of the events pane of the property tab. Select the DataGridView, open the events pane (the one with the flash) and locate the SelectionChanged event! Here insert the name of the event and you are done.
(I only have the German versions of VS installed..)
The result is reflected in the form_designer.cs file and it is the same thing (in reverse) as double clicking that spot and then filling in the generated code stub..
Controls have many events; one is the default event and this can be generated by double clicking the control itself in the designer. But eventually you will need all 3 ways to generate and hook up the events, (as well as sometimes removing them.)
I use a slightly different approach when trying to get data from a datagridview.
Try doing personIDTextBox.Text = DataGridView01.SelectedCells[0].Value.ToString();
but instead of the event being on selection change, switch to CellClick and change the property of the the datagridview row selection property to full row select. after that you can change the SelectedCell[0] number to match whichever cell you want
If you want to display the datagridview selected rows into corresponding textboxes, fine the below steps ,
Step 1:
1. Change the DataGridView Selection mode to FullRowSelect in Datagridview property.
2. Create the cell click event in Data grid view using property.
enter image description here
3. Write the below code and test it, It may helpful
private void DataGridView01_CellClick(object sender,DataGridViewCellEventArgs e)
{
if (DataGridView01.Rows.Count > -1)
{
PersonIdTextBox.Text=DataGridView01.Rows[e.RowIndex].Cells[0].Value.ToString();
comboBox1.Text = DataGridView01.Rows[e.RowIndex].Cells[1].Value.ToString();
Txt_FirstName.Text = DataGridView01.Rows[e.RowIndex].Cells[2].Value.ToString();
mIDDLENAMETextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[3].Value.ToString();
sURNAMETextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[4].Value.ToString();
cITYTextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[5].Value.ToString();
eMAILTextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[6].Value.ToString();
}
}
I have tried to get an answer to this but so far no help has been able to do what I want it to.
I have this piece of code, which is meant to look at the selected row and output it's columns into the corresponding text boxes.
private void DataGridView01_SelectionChanged(object sender, EventArgs e)
{
if (DataGridView01.SelectedRows.Count > 0)
{
personIDTextBox.Text = DataGridView01.SelectedRows[0].Cells[0].Value.ToString();
comboBox1.Text = DataGridView01.SelectedRows[0].Cells[1].Value.ToString();
Txt_FirstName.Text = DataGridView01.SelectedRows[0].Cells[2].Value.ToString();
mIDDLENAMETextBox.Text = DataGridView01.SelectedRows[0].Cells[3].Value.ToString();
sURNAMETextBox.Text = DataGridView01.SelectedRows[0].Cells[4].Value.ToString();
cITYTextBox.Text = DataGridView01.SelectedRows[0].Cells[5].Value.ToString();
eMAILTextBox.Text = DataGridView01.SelectedRows[0].Cells[6].Value.ToString();
}
}
When I launch the program, I get no errors but it doesn't output the data into the textbox. Anyone know what I am doing wrong?
HOOKING UP EVENTS:
It is the most basic thing you need to learn to code in VS. In short it means that the event name, here DataGridView01_SelectionChanged is connected to the event. To do so one can either use code or one inserts it into the correct slot of the events pane of the property tab. Select the DataGridView, open the events pane (the one with the flash) and locate the SelectionChanged event! Here insert the name of the event and you are done.
(I only have the German versions of VS installed..)
The result is reflected in the form_designer.cs file and it is the same thing (in reverse) as double clicking that spot and then filling in the generated code stub..
Controls have many events; one is the default event and this can be generated by double clicking the control itself in the designer. But eventually you will need all 3 ways to generate and hook up the events, (as well as sometimes removing them.)
I use a slightly different approach when trying to get data from a datagridview.
Try doing personIDTextBox.Text = DataGridView01.SelectedCells[0].Value.ToString();
but instead of the event being on selection change, switch to CellClick and change the property of the the datagridview row selection property to full row select. after that you can change the SelectedCell[0] number to match whichever cell you want
If you want to display the datagridview selected rows into corresponding textboxes, fine the below steps ,
Step 1:
1. Change the DataGridView Selection mode to FullRowSelect in Datagridview property.
2. Create the cell click event in Data grid view using property.
enter image description here
3. Write the below code and test it, It may helpful
private void DataGridView01_CellClick(object sender,DataGridViewCellEventArgs e)
{
if (DataGridView01.Rows.Count > -1)
{
PersonIdTextBox.Text=DataGridView01.Rows[e.RowIndex].Cells[0].Value.ToString();
comboBox1.Text = DataGridView01.Rows[e.RowIndex].Cells[1].Value.ToString();
Txt_FirstName.Text = DataGridView01.Rows[e.RowIndex].Cells[2].Value.ToString();
mIDDLENAMETextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[3].Value.ToString();
sURNAMETextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[4].Value.ToString();
cITYTextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[5].Value.ToString();
eMAILTextBox.Text = DataGridView01.Rows[e.RowIndex].Cells[6].Value.ToString();
}
}
I would like to highlight my lastly new create row in my Data grid, I have reference this page http://social.technet.microsoft.com/wiki/contents/articles/21202.wpf-programmatically-selecting-and-focusing-a-row-or-cell-in-a-datagrid.aspx to get some idea.
According to the reference link above datagrid first have to visualise . The reason of the last row is not focus and high light, might be cause by this reason.
Following is my code structure
private void CommitRow(object sender, DataGridRowEditEndingEventArgs e )
{
//FIRE WHEN ROW IS DONE EDIT
/*
STORING DATA TO DATABASE
*/
SelectRowByIndex(Datagrid, Datagrid.Items.Count - 1); //I refer from msdn blog
}
I tried to put the code SelectRowByIndex into a button , it will highlight the last row. Therefore I believe the code will only work when the grid is show up on UI.
My question is how to highlight the last row before interface is show up? or is that any other method allow me to focusing and high light the new create row?
You are correct, it cannot be highlighted, because it isn't rendered yet.
But you can use the dispatcher to your advantage there.
private void CommitRow(object sender, DataGridRowEditEndingEventArgs e )
{
//FIRE WHEN ROW IS DONE EDIT
/*
STORING DATA TO DATABASE
*/
Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
{
SelectRowByIndex(Datagrid, Datagrid.Items.Count - 1);
}));
}
This should do the trick. It calls the Dispatcher to do it with a priority thats just after rendering. Visually this should happen instantly.
During development with Devexpress, we've encountered the use of a InstantFeedbackSource. Using the Row_Loaded, we would like to adjust values of certain rows. Yet the CellContent isn't changed.
Testsolution:
GetQueryable-Method of my datasource:
private void linqInstantFeedbackSource1_GetQueryable_1(object sender, GetQueryableEventArgs e)
{
e.QueryableSource = _testObjects.AsQueryable();
gridView2.RefreshData();
gridControl2.RefreshDataSource();
}
My Row-loaded event
private void gridView2_RowLoaded(object sender, DevExpress.XtraGrid.Views.Base.RowEventArgs e)
gridView2.SetRowCellValue(e.RowHandle, gridView2.Columns["RandomGuid4"], "lalalala");
}
Information:
gridView2.Columns["RandomGuid4"] is not null and refers to the correct-column.
e.RowHandle Refers to the correct Linenumber
Goal:
I want to achieve the following behavior:
At runtime i want to fill the gird with records. When adding the rows i want to check the row for certain values. When a certain value occurs then several another cells should be filled with combobox, hyperlinks,...
The advised way by devexpress is the event CustomCellEdit. But that event is highly unreliable. We're experiencing issues (exceptions from within the control). I've submitted several tickets so far but no response. So we're searching an alternative.
Could someone point out what i'm exactly missing/doing wrong here?
Thank you for your time.
Note: I've tried the use of RefreshData in my RowLoaded-Event but it doesn't appear to be working.
I have a datagrid view which shows table data from a database
Environment:
- C# 4.0
- SQL Server 2005
- Visual studio 2010
What i want is: On a row to row basis automatically save changes. So when I edit the first row and then leave the row. It should save the changes to the database.
I've used this code:
In the From1 Load:
dataSet1.TblObject.RowChanged += rowUpdate;
The eventhandler:
private void rowUpdate(object sender, DataRowChangeEventArgs e)
{
DataRow dr = e.Row;
if (dr.RowState == DataRowState.Modified)
{
tblObjectTableAdapter.Update(dr);
}
}
When I've edited a row in the grid, tblObjectTableAdapter.Update(dr); is called the data is stored to the table. Which is good. But the event keeps on triggering as if it's called recursively. So the tblObjectTableAdapter.Update(dr); is causing a dataSet1.TblObject.RowChanged event. But I can't differentiate between the both of them. I'm guessing I'm using the wrong event to store my values but I can't find any event that sounds logical to me. What am I doing wrong?
I've made a dataset xsd:
I've picked the dataset as datasource in this gridview:
Ok, I read your post a couple of times now, while I can't help u directly with your problem. I'll try anyway, What u want is that when i make a change, it doesn't update itself immediatly, but saves the information in a list and when u press a button save the updates?
Then You should make a List of Datarows, and each time a row is changed add that item to the list, this way the updates aren't made directly, but only when u press the button. (This is also way better for performance sake.)
So instead of the code
DataRow dr = e.Row;
if (dr.RowState == DataRowState.Modified)
{
tblObjectTableAdapter.Update(dr);
}
U should make
DataRow dr = e.Row;
if (dr.RowState == DataRowState.Modified)
{
DatarowLst.Add(dr);
}
ButtonSave_Click(object sender, eventargs e)
{
foreach (DataRow d in DatarowLst)
{
tblObjectTableAdapter.Update(d);
}
}
EDIT:
Ok sorry for misunderstanding u. I now understand your problem and looked into the issue.
I found some interesting information on Data adapters and tables. It seems the Adapter does a row to row check in order to obtain information about the changes made.(i.e does it need a update or delete command?) Thereby, My GUESS is that this triggers a update to occur and therefore call your event again, and running the method recursivly.
Info found at the REMARK piece on: This site from msdn
They give a link to this site for more information. Maybe you'll find your answer there.
As to a solution for your problem it seems u can leave your event out and just call the update command. Im NOT sure about this cause I dont have time to check on this and I have little experience on this subject.
Well, hope this helps u a bit further..