|
I tried to build a Write/Read class as follows:
class DataGridViewColor
{
public static void WriteDataGridViewSettings(System.Windows.Forms.DataGridView dgv)
{
XmlTextWriter writer = new XmlTextWriter(Application.StartupPath + @"\MyGridColor.xml", null);
writer.WriteStartDocument();
writer.WriteStartElement(dgv.Name);
int LastRow = dgv.Rows.Count-1;
for (int i = 0; i < LastRow; i++)
{
for (int j = 0; j < dgv.Columns.Count - 1; j++)
{
writer.WriteStartElement("Color");
writer.WriteStartElement("CellColor");
writer.WriteString(dgv.Rows[i].Cells[j].Style.BackColor.ToString());
writer.WriteEndElement();
writer.WriteStartElement("TextColor");
writer.WriteString(dgv.Rows[i].Cells[j].Style.ForeColor.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
}
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
}
Now, I need to build a class for reading but I don't know how to do that.
Please guide me by giving a code so I can learn something about the solution.
I tried this code but it gives error:
class DataGridViewColor
{
public static void ReadDataGridViewSettings(System.Windows.Forms.DataGridView dgv)
{
XmlDocument xmldoc = new XmlDocument();
XmlNodeList xmlnode;
FileStream fs = new FileStream(Application.StartupPath + @"\MyGridColor.xml", FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
xmlnode = xmldoc.GetElementsByTagName("column");
for (int i = 0; i <= (xmlnode.Count)/13; i++)
{
string cellcolor = xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
string textcolor = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
for (int j = 0; j < 13; j++)
{
dgv.Rows[i].Cells[j].Style = new DataGridViewCellStyle {BackColor = Color.FromName(cellcolor)};
dgv.Rows[i].Cells[j].Style = new DataGridViewCellStyle {ForeColor = Color.FromName(textcolor)};
}
}
fs.Close();
}
}
modified 12-Jan-21 13:12pm.
|
|
|
|
|
please short I remember that when clicking in a cell that the corresponding date evening retrieve and store in a variable. I use a calendar layout like a tables or columns are dates and a column has several cells, I want when I click on a cell to get its corresponding date.
I program in c #
|
|
|
|
|
|
If you want to get an answer to get nearer to your goal you have to provide MUCH MORE information about your control and how it is working.
Of course ... there ist a solution ... but we can't see what you have done until now and we don't have any information about what you are doing ...
If you want to get help : help us ...!!!
|
|
|
|
|
I am fairly new to API's. I am writing a "simple" API that will convert .docx files to .pdf files and return the pdf's back to the client for saving. I have the code working for a single file but I wanted to code the API to handle multiple files in a single request. Now the API is not receiving the request. I can provide the working code with a single file if requested.
I am sure I am missing something simple. Please see below and see if anyone see's something that I could be doing better or why the API is not receiving the POST request.
Client:
List<string> documents = new List<string>();
private async void btnConvert_Click(object sender, EventArgs e)
{
using (var client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }))
{
client.BaseAddress = new Uri(BaseApiUrl);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, BaseApiUrl + ApiUrl);
foreach (string s in docPaths)
{
byte[] bte;
bte = File.ReadAllBytes(docPath);
string data = JsonConvert.SerializeObject(Convert.ToBase64String(bte));
documents.Add(data);
}
using (var formData = new MultipartFormDataContent())
{
foreach (string s in documents)
{
formData.Add(new StringContent(s, Encoding.UTF8, "application/json"));
}
var conversions = documents.Select(doc => client.PostAsync(BaseApiUrl + ApiUrl, formData)).ToList();
await Task.WhenAll(conversions);
var responses = conversions.Select
(
task => task.Result
);
foreach (var r in responses)
{
var s = await r.Content.ReadAsStringAsync();
SimpleResponse res = JsonConvert.DeserializeObject<SimpleResponse>(s);
if (res.Success)
{
byte[] pdf = Convert.FromBase64String(res.Result.ToString());
}
else
{
}
}
}
}
API: This is function that should get the request from the client but it's not being hit.
[HttpPost]
public async Task<List<SimpleResponse>> Post([FromBody]string request)
{
var response = new List<SimpleResponse>();
AIMSConverter convert = new AIMSConverter();
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
foreach (var requestContents in provider.Contents)
{
try
{
}
catch (Exception ex)
{
response.Add(new SimpleResponse() { Success = false, Exception = ex, Errors = new List<string>() { string.Format("{0}, {1}", ex.Message, ex.InnerException?.Message ?? "") } });
}
}
return response;
}
SimpleResponse Model:
public class SimpleResponse
{
public object Result { get; set; }
public bool Success { get; set; }
public Exception Exception { get; set; }
public List<string> Errors { get; set; }
}
|
|
|
|
|
Rather than sending the file content as a Base64-encoded string, you need to send a multipart/form-data request.
You are currently building one request with all of the files attached, and then sending it multiple times - once for each file. You should only send the request once.
Client:
using (var formData = new MultipartFormDataContent())
{
foreach (string document in docPaths)
{
var fileInfo = new FileInfo(document);
var file = new StreamContent(fileInfo.OpenRead());
file.Headers.ContentLength = fileInfo.Length;
formData.Add(file);
}
var responses = await client.PostAsync(BaseApiUrl + ApiUrl, formData);
foreach (var r in responses)
{
... Server:
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
foreach (MultipartFileData file in provider.FileData)
{
try
{
var result = convert.CovertDocToPDF(file, WebConfigurationManager.AppSettings["tempDocPath"], WebConfigurationManager.AppSettings["tempPdfPath"]);
response.Add(new SimpleResponse { Result = result, Success = true });
}
catch (Exception ex)
{
response.Add(new SimpleResponse { Success = false, Exception = ex, Errors = new List<string> { string.Format("{0}, {1}", ex.Message, ex.InnerException?.Message ?? "") } });
}
} Sending HTML Form Data in ASP.NET Web API: File Upload and Multipart MIME - ASP.NET 4.x | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Please I would like to have the C # winforms code, when we click on a cell to enter text it retrieves the corresponding date and stores in a variable
|
|
|
|
|
That's a really bad question. You're going to have to go into a lot more detail about the problem you're having.
"When we click on a cell..." What cell? What control is this? What text are you expecting to be entered?
Nobody is going to write the code for you.
|
|
|
|
|
|
I want to develop an application in windows(I can prefer it over the web too). I want to connect and stream my IP camera and I also want to capture a snapshot of the camera.
I want to know that How can I achieve this?
Are there any free resources to achieve all these requirements?
What I tried so far is the following.
1.I have downloaded the Hikvision web development kit and modified it and successfully achieve all these requirements with the Hikvision web development kit but I am successfully achieving all these until I haven't published the code into IIS after publishing into IIS I am not able to get the functionality.
2.I have tried to implement Ozeki SDK as mentioned in the many blog and sites in my application.
But due to the free trial, Ozeki is showing too much advertisement while streaming.
After all these tries I have posted the question here.
For more detail, I can send the code too.
modified 4-Jan-21 6:54am.
|
|
|
|
|
Member 13327366 wrote: Is there any free resources to achieve all these requirements? Yes, and Google is the place to find them.
|
|
|
|
|
hello Richard MacCutchan,
I don't mean like that.
You got my post in the wrong way.
I request to you too please read the edited question.
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I want to stream the IP cameras of my client into my Windows application.
Please read the edited question for more details.
|
|
|
|
|
|
I am creating a data structure project. My task is to use a 4D linked list and display Linked List in Windows form.
How can I display my linked list data in Winform and How can I use Cut Copy paste functions?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So show us relevant code fragment, explain where you are stuck, tell us what the "4D linked list" contains and what it is used for - we can't help you without information!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Okay... 4 D linked is a linked list that contains 4 pointers (up,down, right, left)
I want to connect the upper text with lower line text and the second line will connect with 1st line down pointer and the down pointer will be linked with lower line upper pointer. If a delete a node It will remove the node and rearrange the linked list. How I can design data structure in c# like this.
|
|
|
|
|
Ah that still does not make much sense - for a data structure use a list with 4 fields.
Connecting text to a field in the selected item of the list text.property = selectedlistitem.up . Can't help with the text property.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I have a DataGridView in my project which loads hundreds of rows from SQL CE file. It contains colorful texts and comboboxes. I searched online and found some solutions. Many of them says that I need to use double buffer. One of those solutions was this:
public static class ExtensionMethods
{
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
}
and:
this.dataGridView1.DoubleBuffered(true);
I use following reference:
using System.Reflection;
My problem is that: 1) DataGridView in above class gives CS0118 error (has red underline)
2) Where should I use
this.dataGridView1.DoubleBuffered(true); ?
modified 3-Jan-21 22:26pm.
|
|
|
|
|
|
I pasted this code at the end of my code lines but IDE gives error.
public partial class myDataGridView : DataGridView
{
public myDataGridView()
{
InitializeComponent();
DoubleBuffered = true;
}
}
The CS0118 eror code for DataGridView
The CS0103 for InitializeComponent and DoubleBuffered
How can I solve the problem?
|
|
|
|
|
|
|