Do you use any DataSource? You better be using it - like DataTable. And when you will do changes in datagridview, all changes will reflct in dataTable as well.
Do you use any DataSource? You better be using it - like DataTable. And when you will do changes in datagridview, all changes will reflct in dataTable as well.
Example:
public DataTable distanciaEclidiana(DataTable dt, DataRow distRefRow, List<string> campos)
{
DataTable newTable = new DataTable("OneColumnTable");
table.Columns.Add("Dist", typeof(float));
DataRow row;
foreach(DataRow dr in dt.Rows)
{
float soma = 0;
foreach (string col in campos)
{
soma += (float)Math.Pow(Convert.ToDouble(distRefRow[col]) - Convert.ToDouble(dr[col]), 2);
}
row = table.NewRow();
row["Dist"] = (float)Math.Sqrt(soma);
}
return table;
}
Now you will be reaturning DataTable!!! Dont forget to change the code on returning.
I am not sure what you need some column, but you can simple add data from the created dataTable to some other.
I hope this it it,
bye
You cannot add rows to dataColumn. You can ONLY add then to dataTable. DataColumn is only a "part" of dataTable, as it is Datarow.
So what i suggest you, is that you add new column to dataTable, and then add data to this column (you do NOT need to add rows, because rows already exists).
If you dont want to add column to existing datatable, create a NEW dataTable, and then create a new datacolumn (as you already did) and then use table.NewRow() method.
An ObjectListView will do exactly that and much more. It is a wrapper around a normal .NET ListView. It is open source.
Its website has a Getting Started to help you begin, as well as a whole page devoted to cell editing.
Otherwise I would stringly suggest you to use othe control, DataGridView, which is meant for this job. ListVIew is meant only for showing data, not for editing.
There is many methods to do the checking, one (and most common) is to use TryParse method:
int myNumber = 0;
if(int.TryParse(textBox1.Text, out myNumber))
{
//this is a number,
}
else
{
MessageBox.Show("Sorry, string is not a number.");
textBox1.Text = string.Empty;
}
Then do:
string[] LinesFile = streamReader.ReadToEnd().Split('\n');
for(int i = 0; i < LinesFile.Lenght; i++)
{
for(int j = 0; j < LinesFile[i].Lenght; j++)
{
string[] LinesData = string.Split(',');
foreach(string item in LinesData)
{
Console.WriteLine(item);
}
}
}
Console.ReadLine();
If I get your correctly, you populate DGV with some values: name, surname, and another surname - all in one cell. Now you would like to split this cell into name, and lastnames?
If Iam correct, Split it by whitespace:
Dim data As String() = dataGridView1.Rows(0).Cells(0).Value.ToString().Split(" "C)
'data array now has all name and lastname(s).
Use array data in your code.
What you you select all (one by one, but all eventually)? Isnt this a bid odd?
Or did you mean something else?
Are these files in one folder? If so, you can get all files from this folder into a FileInfo[] (you need fileInfo, because you need a full path, so set files back where they were before renaiming).
Then you do some additional code of renaiming and use Move method for an actual renaiming:
string path =@"C:\MyFolder";
FileInfo[] files = new DirectoryInfo(path).GetFiles("*.txt");
for (int i = 0; i < files.Length; i++)
{
string newFile = String.Format("{0}{1}.{2}", "File", (i + 1), "txt");
string fullNewPath = files[i].DirectoryName;
File.Move(files[i].FullName, Path.Combine(fullNewPath, newFile));
}
I hope you like it.
And what will be the difference between 1st and 2nd rectangle? Will you create n number of rectanlges (and where to position it/them)?
... with the help of mouse by clicking on button line should be displayed on panel and if first rectangle should not b disappeared...
Hi,
I don`t understand these words. Can you please elablrate it better?
Thx in advance.
I dount. I dont think so.
But if this is only the look you want do have (so from 2 forms will be look like 1), you can do the following:
- put all the controls on each form intoa userControl (together with the code of course)
- create a third form (new one) and use those two userControls on it!
I cant see any other reasonable solution to this. I havent even heard of it before.
Here is what you can do:
I would use a backgroundworker, and do the download work in it:
private delegate void DownloadDelegate(string msg);
private BackgroundWorker bgv;
public Form1()
{
InitializeComponent();
//create bgv:
bgv = new BackgroundWorker();
bgv.ProgressChanged += new ProgressChangedEventHandler(bgv_ProgressChanged);
bgv.DoWork += new DoWorkEventHandler(bgv_DoWork);
bgv.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgv_RunWorkerCompleted);
//label will be used as a note of a progress
label1.Text = "";
//creating columns:
DataGridViewButtonColumn btnColumn = new DataGridViewButtonColumn();
btnColumn.HeaderText = "Dowload";
btnColumn.Name = "column2";
btnColumn.Text = "download";
btnColumn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add("column1", "Text Name");
dataGridView1.Columns.Add(btnColumn);
//adding some example rows:
for (int i = 1; i < 6; i++)
dataGridView1.Rows.Add("Test number " + i);
//adding event:
dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dataGridView1.Columns["column2"].Index)
{
//disable dgv until download runs our:
//dataGridView1.Enabled = false;
bgv.RunWorkerAsync();
//disable dgv:
dataGridView1.Enabled = false;
}
}
void bgv_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (!(e.Error == null))
label1.Text = "Error: " + e.Error.Message;
else
{
label1.Text = "Done!";
//enable dgv:
dataGridView1.Enabled = true;
}
}
void bgv_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
worker.WorkerReportsProgress = true;
worker.WorkerSupportsCancellation = true;
//
//THIS IS WHERE YOU PUT YOUR DOWNLOAD CODE!!!
//
//this is only my example code of time consuming:
int total = 50; //some variable
for (int i = 0; i < total; i++)
{
if (worker.CancellationPending)
{
e.Cancel = true;
break;
}
else
worker.ReportProgress((100 * i) / total);
//stop a bit:
System.Threading.Thread.Sleep(50);
}
}
void bgv_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
label1.Text = " …
Why would you do an even for some button inside other button? This makes no sence.
Events for all the button can be generated on the load time. Or when you create some button in the run time (afterwards).
If you still inisit you can do it:
private void button6_Click(object sender, EventArgs e)
{
//just make sure your button initialized on form!!
this.button7.Click += new EventHandler(button7_Click);
EvenArgs ee = new EventArgs();
button7_Click(this.button7, ee); //this will fire button event!
}
private void button7_Click(object sender,EventArgs e)
{
MessageBox.Show("Button7 Clicked when ur pressing button6");
}
You have to add rows as well (every loop):
int clicks = 0;
private void button4_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[clicks].Cells["Author_Number"].Value = "Author " + (clicks + 1).ToString();
dataGridView1.Rows[clicks].Cells["First_name"].Value = "fname";
dataGridView1.Rows[clicks].Cells["Last_name"].Value = "lname";
clicks++;
}
Why would you do a for loop? I dont see any reasonable reson why use it.
Please explain why would you use a for loop?
Use this pattern to all:
Dim a As Decimal = 6.25D
//pattern:
Dim fraction As Decimal = a - CInt(Math.Truncate(a))
a = a - fraction + (0.95D)
mysqlda.UpdateCommand.Parameters.Add("@Price", MySqlDbType.Decimal ,10,2, "Price");
The 3rd parameter in the Add() method is the Size, and its must me an integer. So no commas in between. You dont specify and such thing as in the database, where you specify the number of decimals (like 10, 2 - 10 numbers lenght,and precision of these 2 decimals).
Here you only specify the size of the value).
It represents The maximum size, in bytes, of the data within the column.
This parameter is not so important, because Size affects only the input value of a parameter. Return values and output parameters are not affected by this property.
You can set the size to -1, to ensure that you are getting the entire data from the backend without truncation.
Here is what you can all set for particular parameter:
SqlParameter myParameter = new SqlParameter("@Price", SqlDbType.Decimal);
myParameter.Value = /some value
myParam.Size = -1; //or you can set it to 5
myParameter.Precision = 8;
myParameter.Scale = 4;
This is only to show you how you can set parameters for a SqlParameter class.
You can do something like this:
mysqlda.UpdateCommand.Parameters.Add("@Price", MySqlDbType.Decimal ,5, "Price");
alt + w (in european keyboards)
Did you thing using only:
//now u can save changes to back end with
da.Update(ds);
will save the changes to the dataBase? Nope. YOu need some other code for UPDATE as well.
What does the SqlCommand for Update look like? I see the command but I don't see any SqlText, that's what you're missing.
You need to define what .Update does by setting .UpdateCommand property on the SqlDataAdapter
This link gives a pretty good breakdown on how to go about it here.
Not true, it wont help.
This is what you can try:
da.Fill(ds,"myTable");
dgv1.DataSource = new BindingSource(ds.Tables["myTable"], null); //but the same as using names is using table indexes, like you did!
1st you need to create columns, then you fill the row (by looping through rows of dgv):
DataSet ds = new DataSet();
DataTable table = new DataTable("DataFromDGV");
//if you have only one table, it pointless to create a dataSet
//dataSet is used as a collection of more-then-one dataTable
//so you can do:
ds.Tables.Add(table);
//create columns:
foreach(DataGridViewColumn col in dgv.Columns)
table.Columns.Add(col.HeaderText, typof(string));
//fill the rows of table:
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
table.Rows[row.Index][cell.ColumnIndex] = cell.Value;
}
}
Great. If this is it, you can complete the thread with setting it as answered.
If not, you can still ask questions ,regarding the thread`s topic.
Best regards,
Try it this way:
Dim days As Integer = 12 'your value from DB! (one or the other - didnt know what you want
Dim months As Integer = 5 'your value from DB!
Dim [date] As DateTime = DateTime.Now 'some date !
'get new date (current date + days):
[date] = [date].AddDays(days)
'get new date (current date + months):
[date] = [date].AddMonths(months)
Would you mind showing us the code you got there? Maybe we can figure something out.
And tell us your logic about fasering the procedure of file creation.
Momerath had to point. What does it take so much to co create 100 files?
Next - if your code (and computer) is capable of 100 per 10 minutes, then this is it! You actually cant make the same files two times faster.
Process.Start(); executes the code to start some application or something.
Dim myProcess As System.Diagnostics.Process = System.Diagnostics.Process.Start("Notepad")
will start the Notpad.
What did you mean to start?
This one would be a better choice:
Private Sub button1_Click(sender As Object, e As EventArgs)
ExecuteMyCode(textBox1.Text)
End Sub
Private Sub ExecuteMyCode(text As String)
If text.Contains("me.text") Then
Dim array As String() = text.Split("="C)
Me.Text = array(1)
Else
MessageBox.Show(text)
End If
End Sub
Ok, I have choosen a button click, but you can easiy use this code in TextChanged event too:
UPDATED:
Private Sub button1_Click(sender As Object, e As EventArgs)
ExecuteMyCode(textBox1.Text)
End Sub
Private Sub ExecuteMyCode(text As String)
Dim data As String() = text.Split(" "C)
If data.Length > 1 Then
Select Case data(0)
Case "msgbox.show"
MessageBox.Show(data(1))
Exit Select
Case "me.text"
Me.Text = data(1)
Exit Select
Case Else
'do nothing is non of above
Exit Select
End Select
Else
MessageBox.Show("Data is missing to show.")
End If
End Sub
Still some work to do on to show correct result! We need to gather data!
On a button click or on textChnaged event?
I assume you are dealing with Access database, thats why you are trying to use question marks (???) when defining Values(in here), righ?
Correct way, only some part is missing.
You actually have to specifry the column names and not using question marks. Questio marks are only used in Update statement.
Do you type in textBox both vlaues?
So your textbox after finishing writing looks like:
textbox "label1.text = "bla bla"" "msgbox.show"
With or without quotation marks?
This is getting pointeless mate!
For UPDATE statement you do:
UPDATE tableName SET Field1 = @param1, Fields2 = @param2 WHERE idFields = @paramID
INSERT statement should go like:
INSERT INTO DataBaseTable VALUES (value1, value2, ...)
So, yours statement is incorrect.
Is it Express version?
It means your value can NOT be converted to float. Its just not that object to cast.
Set break point, and go to check what kind of value has "strUntitPrice".
Where, on which line of code this error appears? Please use a break point.
Here you go:
public Form1()
{
InitializeComponent();
//adding some example columns:
//1. column is checkBox, rest of 2 are some usual column:
DataGridViewCheckBoxColumn checkColumn = CreateCheckBoxColumn();
dataGridView1.Columns.Add(checkColumn);
dataGridView1.Columns.Add("col2", "Column 2");
dataGridView1.Columns.Add("col3", "Column 3");
//adding some example rows:
for (int i = 1; i <= 10; i++)
{
dataGridView1.Rows.Add(false, "item A" + i, "item B" + i);
}
//create an event:
dataGridView1.CurrentCellDirtyStateChanged += new EventHandler(dataGridView1_CurrentCellDirtyStateChanged);
dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}
private DataGridViewCheckBoxColumn CreateCheckBoxColumn()
{
DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
{
column.Name = "checkColumn";
column.HeaderText = "Select rows";
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
column.ThreeState = false;
}
return column;
}
void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
private void dataGridView1_CellValueChanged(object obj, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dataGridView1.Columns[0].Index) //compare to checkBox column index
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (!row.IsNewRow)
{
DataGridViewCheckBoxCell checkBox = dataGridView1[0, row.Index] as DataGridViewCheckBoxCell;
if (checkBox != null)
{
if ((bool)checkBox.Value == true)
dataGridView1.Rows[row.Index].Selected = true;
else
dataGridView1.Rows[row.Index].Selected = false;
}
}
}
}
}
Try to chanve dateChanged with dateSelectec event.!
//1. to get a total of LastBalace:
"SELECT SUM(LastBalance) FROM Students";
//2. to get the last LastBalance
"SELECT MAX(LastBalance) FROM Students";
//3. to get a specifc lastBalance
"SELECT LastBalance FROM Students WHERE StudentID = @id";
//pass an integer value to @id parameter!
/use SqlCommand(of OleDbCommand for Access) class.
//And use SqlDataReader class to read the value!
I have a Textbox named txtage.text.Now I want When Insert in txtage.text as 30/12/1980.
disable tabindex.and messagebox show "You can not give admission".If Insert in txtage.text as 30/12/2005.
Enable Tab index .its mean student 's age must be 6 year not greater nor less.
1st of all, your post in not clear. Make is so, if you wanna help from us.
About what/which tabIndexes are you talkin about?
And when you work with dates, its best to use a control which is meant for it - so dateTimePicker as ddanbe told you.
You can simply disable textBox:
txtage.Enabled = false;
I can see you use DataTable as a binding source to the dgv control.
So you can use filtering on the dataTable, with a help of "SELECT" method:
Private table As DataTable
Public Sub New()
InitializeComponent()
table = New DataTable("MyTable")
table.Columns.Add("Id", GetType(Integer))
table.Columns.Add("Name", GetType(String))
table.Columns.Add("Car", GetType(String))
table.Rows.Add(1, "Name 1", "Ferrari")
table.Rows.Add(2, "Name 2", "Jaguar")
table.Rows.Add(3, "Name 3", "Ferrari")
table.Rows.Add(4, "Name 4", "Porsche")
table.Rows.Add(5, "Name 5", "Ferrari")
table.Rows.Add(6, "Name 6", "Porsche")
dataGridView1.DataSource = New BindingSource(table, Nothing)
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
Dim myFilter As String = "Ferrari"
Dim newTable As DataTable = New DataView(table, "Car = '" & myFilter & "'", "Name DESC", DataViewRowState.CurrentRows).ToTable()
dataGridView1.DataSource = Nothing
dataGridView1.DataSource = New BindingSource(newTable, Nothing)
End Sub
NOTE: "Car = 'Ferrari' is an actual filter. So in your case myFilter variable is set to some textBox, which will be used to filter dgv.
String strFile = File.ReadAllText("c:\\File1.txt");
strFile = strFile.Replace("oldvalue", "newvalue");
File.WriteAllText("c:\\File1.txt", strFile);
What kind of data do you have, and what to replace?
thx for the answer.
No need. Just ask here.
If you wanna store more picture of one patient, you cannot (or its not a good practice) to store more then one into one cell of a table.
Instead of that, I strongly suggest you to create a new Table which will be only for patient`s images. It will have only a foreigh key of patient, image name, and image it self (in byte array).
This way you can store as many pictures as you like for one patient. So DB shoud look like:
TABLENAME: field1, fields2, ...
PATIENT: PatientID, Name, LastName, ...
PATIENT_PICTURES: PatientID_FK(int), ImageName(varchar,50), Picture(byte)
You got my point?
You still didnt answer on ny question: Do you wanna loop through the images of patients? Will you have any buttons (Next, Back)?
If you you can do an ImageList, and loop through them while pressing on one of those tow buttons.