hello Sir i am creating a POS and i want to multiply two columns in gridview and show result in it how can i do it?
DataGridView column multiplication
How to catch event when user start typing text in gridview cell?
ACCESS adding PrimaryKey
Error : string was not recognized as a valid Timespan...
Hi everyone,
I need some immediate help from this error..I am passing values from datagridview selected row to form..I have one column name called "timeout" in that column I am storing time value..when I double click on any row all the values are passing from datagridview to form except the time value..don't know how to convert datagridview time value for passing..
Here is my snapshot:
the above datagridview time wants to display on timeout filed when i double click on any row...
Error snap:
Here is my conversion code:
this.dtptime.Value = System.DateTime.Now.Add(TimeSpan.Parse(row.Cells["Time_out"].ToString()));
Thanks & Regards RAJENDRAN M
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function
Private Sub m_dtgControlTiempos_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles m_dtgControlTiempos.CellEndEdit
Dim nextIndex As Integer = Math.Min(m_dtgControlTiempos.ColumnCount - 1, m_dtgControlTiempos.CurrentCell.ColumnIndex + 1)
m_dtgControlTiempos.CurrentCell = m_dtgControlTiempos.CurrentRow.Cells(nextIndex)
m_dtgControlTiempos.BeginEdit()
End Sub
but it throws me an exception: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function
If I change the variable nextIndex for a integer literal it works.
Any solution?
How to disable Microsoft Report render last page?
I encounter a special requirement, i use Microsoft Report for windows form application
I want to prevent the Report from Rendering it's last page.
anyway, i would show the all report pages in viewer except for last page.
Could i ? and How.
thanks.
DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.
How To Pass textbox Value from form1 to form 2 variable or another control in C#?
I have seen some example, but it is not clear for me.
Let say I have form1 in form one I have a textbox. After typing on the text box, how can I pass that value on form 2 variable or control? Thanks.
Datagridview after loading
I have a datagridview which gets loaded on the page load. I noticed a few interesting problems with the datagridview. When the datagridview loads it selects the first row by default and when I select a different row it goes through the cellbeginedit event:
privatevoid dgvPurchaseOrderToReceive_CellBeginEdit(object sender,DataGridViewCellCancelEventArgs e)
{
if (loadingDataGridView) return;
if (e.ColumnIndex == 0 && e.RowIndex > -1 && (bool)dgvPurchaseOrderToReceive.Rows[dgvPurchaseOrderToReceive.CurrentCell.RowIndex].Cells[0].FormattedValue ==false)
{
if (receivedAmount == Convert.ToInt32(dgvPurchaseOrderToReceive.CurrentRow.Cells["Received"].Value))
{
e.Cancel =true;
Validation.ShowMessage(Main.lblStatus,"Item already fully received!");
}
}
}
It says "Item already fully received even though it's not true the row that we left was fully received not the row we are coming into.
But even though I didn't select the first column when debugging it thinks the first column first row is being selected. This only happens the first time the datagridview loads after that it all works fine. What can I do about it?
Also, when on the form closed event I check if any of the datagridview checkboxes are checked it should give a message "Would you like to save before closing." Which works nicely except when I check something off and don't yet do any other event just x the screen it doesn't yet realize that there is a row checked in the datagridview.select("checked = 'true'")
Debra has a question
WPF view dropdown list one below the other
I am just learning WPF in MVVM. In the view I want the drop down list to be beside each other. But its coming one below the other. Below is my code sinpet.
<Window.Resources>
<DataTemplate DataType="{x:Type vm:EmployeeListviewModel}">
<vw:EmployeeListview/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:ProjectListViewModel}">
<vw:ProjectListView/>
</DataTemplate>
</Window.Resources>
Regards
Raghu
datatable.select doesn't always work
I have a datatable that has a checkbox column which corresponds to a checkbox in a datagridview I would like to be able to do
foreach(datarow row in dt.select("Checked = 'true'")
{
}
but it gives all the checked rows minus the first one why is that?
In general I find that the .select doesn't always pick up on everything right away or ever, while the
foreach(datarow row in dt.rows)
{
if(Convert.toboolean(row["Checked"]) == true)
}
catches everything.
Debra has a question
datagridview check box column error
I have a checked column in a datatable which I bind to a datagridview. In this case I don't want the checkbox column in the datagridview to show so I do dgv.columns["checked"].visible = false;
when that is done it gives me an error for the line dgv.currentrow... "object reference not set to an instance of an object."
when it's visible it doesn't give me the error. Why is that?
Debra has a question
DataAdapter.Update not working
I am just having a simple table testxmlmsg with 4 fields, serno, timestamp, bytexmlmsg, userid.
The serno is set as primary.
I am trying to update the data using the bellow function. No error or exception is coming but the data are not getting updated in the database.
Note that I do not want to use the QueryBuilder.
Thanks in advance for any help.
----------------------------------------------------------------------------------------------------------------------------
Private Sub updateRecord()
Dim connection As IfxConnection
Dim Transaction As IDbTransaction
Dim DataAdapter As IfxDataAdapter = New IfxDataAdapter
Dim UpdateCommand As IfxCommand
Dim SelectCommand As IfxCommand
Try
connection = New IfxConnection(txtConnection.Text)
connection.Open()
Try
Transaction = connection.BeginTransaction()
Try
Dim data As DataSet = New DataSet
UpdateCommand = connection.CreateCommand
SelectCommand = connection.CreateCommand
SelectCommand.CommandText = "SELECT userid FROM testxmlmsg"
SelectCommand.Transaction = Transaction
SelectCommand.Connection = connection
DataAdapter.SelectCommand = SelectCommand
UpdateCommand.Transaction = Transaction
UpdateCommand.Connection = connection
UpdateCommand.CommandText = "UPDATE testxmlmsg SET userid = 2"
DataAdapter.UpdateCommand = UpdateCommand
DataAdapter.Fill(data)
Dim cRow As DataRow
For Each cRow In data.Tables(0).Rows
cRow(0) = 2
Next
DataAdapter.Update(data)
data.AcceptChanges()
Catch exc As Exception
txtUpdateError.Text = exc.Message
End Try
Catch exc As Exception
txtUpdateError.Text = exc.Message
Finally
connection.Close()
End Try
Catch exc As Exception
txtUpdateError.Text = exc.Message
Finally
connection.Dispose()
End Try
End Sub
Multiple Tables in one DataGridView
Hi, i'm trying to make a DatagridView filled with the information of two related tables. I've tried binding the DataGridView with the relation but only one table is shown. I also tried searching for the solution and found out that the old Datagrid was able to display related data by clicking on a "+", why is the new Datagrid not able to do something similar? I'm using Visual Basic 2008 and Mysql and any help would be appreciated.
Forcing a user control in a datagridviewcell to be displayed over other cells?
Hi there everyone,
I have been searching for a long time and cannot seem to find the answer i am looking for;
What I want is a a complex user control to be inserted into each cell.
What I have done is follow these posts, except now just use a custom control instead of the datetimepicker.
However the custom control is only being displayed in the cell and will not overlap.
Some googling has shown that the best method of resolving this issue is making the user control from the base class of dropdownlist.
Any help will greatly be appreciated.
This is what I have so far: (which is basically https://msdn.microsoft.com/en-us/library/7tas5c80(v=vs.110).aspx)
public class ItemListBoxCell : DataGridViewTextBoxCell { public ItemListBoxCell() : base() { // Use the short date format. // this.Style.Format = "d"; } public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { // Set the value of the editing control to the current cell value. base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); ItemListBoxEditingControl ctl = DataGridView.EditingControl as ItemListBoxEditingControl; } public override Type EditType { get { // Return the type of the editing control that CalendarCell uses. return typeof(ItemListBoxEditingControl); } } public override Type ValueType { get { // Return the type of the value that CalendarCell contains. return typeof(string); } } public override object DefaultNewRowValue { get { // Use the current date and time as the default value. //return DateTime.Now; return ""; } } } class ItemListBoxEditingControl : TestControl, IDataGridViewEditingControl { DataGridView dataGridView; private bool valueChanged = false; int rowIndex; public ItemListBoxEditingControl() { //this.Format = DateTimePickerFormat.Short; } // Implements the IDataGridViewEditingControl.EditingControlFormattedValue // property. public object EditingControlFormattedValue { get { //return this.Value.ToShortDateString(); // return this.SelectedText.ToString(); return this.ToString(); } set { if (value is String) { try { // This will throw an exception of the string is // null, empty, or not in the format of a date. // this.Value = DateTime.Parse((String)value); } catch { // In the case of an exception, just use the // default value so we're not left with a null // value. //this.Value = DateTime.Now; } } } } // Implements the // IDataGridViewEditingControl.GetEditingControlFormattedValue method. public object GetEditingControlFormattedValue( DataGridViewDataErrorContexts context) { return EditingControlFormattedValue; } // Implements the // IDataGridViewEditingControl.ApplyCellStyleToEditingControl method. public void ApplyCellStyleToEditingControl( DataGridViewCellStyle dataGridViewCellStyle) { this.Font = dataGridViewCellStyle.Font; //this.CalendarForeColor = dataGridViewCellStyle.ForeColor; //this.CalendarMonthBackground = dataGridViewCellStyle.BackColor; } // Implements the IDataGridViewEditingControl.EditingControlRowIndex // property. public int EditingControlRowIndex { get { return rowIndex; } set { rowIndex = value; } } // Implements the IDataGridViewEditingControl.EditingControlWantsInputKey // method. public bool EditingControlWantsInputKey( Keys key, bool dataGridViewWantsInputKey) { // Let the DateTimePicker handle the keys listed. switch (key & Keys.KeyCode) { case Keys.Left: case Keys.Up: case Keys.Down: case Keys.Right: case Keys.Home: case Keys.End: case Keys.PageDown: case Keys.PageUp: return true; default: return !dataGridViewWantsInputKey; } } // Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit // method. public void PrepareEditingControlForEdit(bool selectAll) { // No preparation needs to be done. } // Implements the IDataGridViewEditingControl // .RepositionEditingControlOnValueChange property. public bool RepositionEditingControlOnValueChange { get { return false; } } // Implements the IDataGridViewEditingControl // .EditingControlDataGridView property. public DataGridView EditingControlDataGridView { get { return dataGridView; } set { dataGridView = value; } } // Implements the IDataGridViewEditingControl // .EditingControlValueChanged property. public bool EditingControlValueChanged { get { return valueChanged; } set { valueChanged = value; } } // Implements the IDataGridViewEditingControl // .EditingPanelCursor property. public Cursor EditingPanelCursor { get { return base.Cursor; } } /* protected override void OnSelectedValueChanged(EventArgs eventargs) { // Notify the DataGridView that the contents of the cell // have changed. valueChanged = true; base.OnSelectedValueChanged(eventargs); this.EditingControlDataGridView.NotifyCurrentCellDirty(true); //base.OnValueChanged(eventargs); }*/ }
and then the custom control with a simple button, for testing.
private void buttonclick(object sender, EventArgs e) { MessageBox.Show("test"); }
how I apply this usercontrol to the datagridview is by doing a db query, binding the data and then changing the columns like this
DataGridViewCell listboxcell = new ItemListBoxCell(); ItemDatagridView.Columns[2].CellTemplate = listboxcell;
Also this is very new to me.. So please go easy on me..
Datagridview doesn't horizontally scroll to the end
I have a datagridview control that I programatically scroll horizontally and vertically from a search box on top. It scrolls down to the bottom very nicely but it doesn't scroll all the way to right it stops a little before and I'm not sure why?
Below is the scrolling code:
privatevoid txtSearch_KeyDown(object sender,KeyEventArgs e)
{
isKeyPress =true;
if (e.KeyCode.Equals(Keys.Left))
{
dgvList.MoveDataGridViewColumnLeft();
return;
}
if (e.KeyCode.Equals(Keys.Right))
{
dgvList.MoveDataGridViewColumnRight();
return;
}
if (e.KeyCode.Equals(Keys.Up))
{
bs.MovePrevious();
return;
}
if (e.KeyCode.Equals(Keys.Down))
{
if (dgvList.CurrentCell == null) dgvList[0, 0].Selected = true;
else
{
bs.MoveNext();
}
return;
}
}
publicstatic void MoveDataGridViewColumnLeft(this DataGridView sender)
{
try
{
int ColumnCount = sender.ColumnCount - 1;
int ColumnIndex = sender.CurrentCell.ColumnIndex;
int RowIndex = sender.CurrentCell.RowIndex;
if (ColumnIndex - 1 > -1)
{
int ProposedColumnIndex = ColumnIndex - 1;
int NewColumnIndex = 0;
if (sender.GetLastVisibleColumn(ref NewColumnIndex))
{
if (ProposedColumnIndex <= NewColumnIndex)
{
sender.CurrentCell = sender[ProposedColumnIndex, RowIndex];
}
else
{
sender.CurrentCell = sender[ColumnIndex - 1, RowIndex];
}
}
}
}
catch
{
}
}
publicstatic void MoveDataGridViewColumnRight(this DataGridView sender)
{
try
{
int ColumnCount = sender.ColumnCount - 1;
int ColumnIndex = sender.CurrentCell.ColumnIndex;
int RowIndex = sender.CurrentCell.RowIndex;
if (ColumnIndex + 1 <= ColumnCount)
{
int ProposedColumnIndex = ColumnIndex + 1;
int NewColumnIndex = 0;
if (sender.GetLastVisibleColumn(ref NewColumnIndex))
{
if (ProposedColumnIndex > NewColumnIndex)
{
sender.CurrentCell = sender[NewColumnIndex, RowIndex];
}
else
{
sender.CurrentCell = sender[ColumnIndex+ 1, RowIndex];
}
}
}
}
catch
{
}
}
I use this code in numerous places and it works fine. Just in one case it doesn't work.
Debra has a question
Unable to perform grid operations
Hi,
We are having a Windows application called Talisma CRM, which we are trying to automate using CodedUI. It is having a data grid which we were not able to identify using coded UI, then we used "DevExpress" extension and we are able to identify the grid, though we are unable to perform any actions on the grid. such as, get the row data, identify a particular cell and getting the data from the cell etc.,
When we try to access the grid it gives controltype : Client, Technology : MSAA
We contacted vendor and they gave the below information regarding the grid.
"It is CListCtrl in MFC. Wrappers have been built around that".
Could you please suggest us what extensions do we need to use in order to access the grid and perform grid operations.
Regards,
Santhoshi
Duplicate Designer.vb file when saving dataset
Of course, the project will not build unless you delete the dataset1.designer.vb file.
Any help would be appreciated.
Luis
Luis R. Lebron
Problem with BindingSource.Find on Relational BindingSource
When attempting to use BindingSource.Find ("QuestionID", SearchKey), I get the followinng error: "DataMember property 'QuestionID' cannot be found on the DataSource."
I noticed the DataMember property for BindingSource1 is "FK_Question_Exam" and the DataSource property is BindingSource0. This must be what makes the relational aspect work.
I have seen one other post on the forum describing the same problem, but there was no resolution.
How to remove all rows in a DataGridView
I have a DataGridView that takes data from a textbox that user inputs. Then, a button that lets user save all rows to database. After saving, I want to remove all rows in the DataGridView. However, the DataGridView always keeps one row undeleted. My code is:
private
void button2_Click(object sender, EventArgs e){
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows.RemoveAt(i);
}
}
What is wrong with my code?
Thanks,
Blinking DataGridViewRow ErrorText
Hello all,
I have a DataGridViewCellValidating function that sets the error text based on a particular cell's input. It calls a function called "HighlightErrantCell" which ensures the user cannot leave the problem cell without fixing it.
A MessageBox seems abrupt, but I would like some kind of animation so the user doesn't think my application is frozen when they try to click another cell. I put a loop at the end of my HighlightErrorCell, but it doesn't do anything I notice.
Here's what I have so far:
private void HighlightErrantCell(int RowIndex) { string err = grdUsers.Rows[RowIndex].ErrorText; //Focus on the proper cell based on the error text. . . . //Animate the ErrorText flashing for (int i = 1; i <= 3; i++) { System.Diagnostics.Debug.WriteLine("Clearing Error text."); grdUsers.Rows[RowIndex].ErrorText = null; grdUsers.UpdateRowErrorText(RowIndex); grdUsers.InvalidateRow(RowIndex); System.Threading.Thread.Sleep(300); System.Diagnostics.Debug.WriteLine("Setting Error text."); grdUsers.Rows[RowIndex].ErrorText = err; grdUsers.UpdateRowErrorText(RowIndex); grdUsers.InvalidateRow(RowIndex); System.Threading.Thread.Sleep(300); } }Thank you in advance.