我有DropDownList以下选项:
o select
1 hot
2 cold
3 warm
Run Code Online (Sandbox Code Playgroud)
如何从中获取最后一个选项值("暖")DropDownList?
如何将包含1000行的单个文本文件拆分为多个较小的文件,例如每行300行?请记住,原始文件可能有多于或少于一千行.
file1.txt 300 lines -> rest
file2.txt 300 lines -> rest
file3.txt 300 lines -> rest
file4.txt 100 lines
Run Code Online (Sandbox Code Playgroud)
我试过以下但是没有用.
int counter = 0;
string line;
string lineoutput = (current_dir + "\\" + DateTime.Now.ToString("HHmmss") + ".txt");
System.IO.StreamReader inputfile;
inputfile = new System.IO.StreamReader(new_path);
while ((line = inputfile.ReadLine()) != null)
{
System.IO.StreamWriter file = new System.IO.StreamWriter(current_dir + "\\" + DateTime.Now.ToString("HHmmss") + ".txt", true);
string _replaceBackspace = ReplaceBackspace(read_file.ReadLine().ToLower());
using (StreamWriter writer = new StreamWriter(lineoutput, true))
{
if (counter == 5000)
{
counter = …Run Code Online (Sandbox Code Playgroud) 有人可以给我有2个变量的代码.1变量保存日期,其他显示为longdate格式.
我正在尝试对文本框使用 SelectionStart 和 SelectionLength 属性。它没有效果,但也没有错误。它实际上是后台工作人员 ProgressChanged 方法的一部分,但我已经在测试解决方案中单独尝试了 SelectionStart 和 SelectionLength 并且它是相同的......没有任何反应......
有任何想法吗?谢谢!!!
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Update the GUI as the music is playing
textBox1.SelectionStart = ((int)e.UserState);
textBox1.SelectionLength = (1);
}
Run Code Online (Sandbox Code Playgroud) 当我更改行中任何单元格的值时,我想动态更改同一行中的其他单元格.例如,在以下网格中,当我在第二行中将1更改为3时,值5必须更改为3. (编辑按钮仅将更改保存到数据库中.)

这是我的xaml代码DataGrid.我尝试过使用SelectedCellsChanged和SelectionChanged事件,但我没有成功.
<DataGrid x:Name="MyDataGrid" x:Uid="MyDataGrid" AutoGenerateColumns="False"
Height="226" HorizontalAlignment="Left" Margin="106,111,0,0"
VerticalAlignment="Top" Width="684" ColumnWidth="*"
AlternationCount="2" SelectionMode="Single"
SelectedCellsChanged="MyDataGrid_SelectedCellsChanged"
SelectionChanged="MyDataGrid_SelectionChanged" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=ProductName}" Header="Ürün Ad?" />
<DataGridTextColumn Binding="{Binding Path=StoreName}" Header="?ube Ad?" />
<DataGridTextColumn Binding="{Binding Path=Day1}" Header="Pazartesi" />
<DataGridTextColumn Binding="{Binding Path=Day2}" Header="Sal?" />
<DataGridTextColumn Binding="{Binding Path=Day3}" Header="Çar?amba" />
<DataGridTextColumn Binding="{Binding Path=Day4}" Header="Per?embe" />
<DataGridTextColumn Binding="{Binding Path=Day5}" Header="Cuma" />
<DataGridTextColumn Binding="{Binding Path=Day6}" Header="Cumartesi" />
<DataGridTextColumn Binding="{Binding Path=Day7}" Header="Pazar" />
<DataGridTemplateColumn Header="Edit Row">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Edit" Click="EditButton_Click" …Run Code Online (Sandbox Code Playgroud) 我有以下内容:
String sql = "SELECT * FROM Temp WHERE Temp.collection = '" + Program.collection + "'";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(sql, conn);
Program.defaultCollection = (String)cmd.ExecuteScalar();
Run Code Online (Sandbox Code Playgroud)
我想在执行语句后得到第二列.我知道它只返回一行有两列
我在网上看过,我必须阅读结果的每一行,还有其他方法吗?
我有一个媒体元素播放的视频文件.我需要继续玩,所以我试过:
me.play();
me.MediaEnded += new RoutedEventHandler(me_MediaEnded);
Run Code Online (Sandbox Code Playgroud)
使用此事件方法:
//loop to keep video playing continuously
void me_MediaEnded(object sender, EventArgs e)
{
//play video again
me.Play();
}
Run Code Online (Sandbox Code Playgroud)
但是,上面没有重播视频文件.为什么?我做错了什么?
我正在使用DataGridView来显示来自SQLite数据库的数据。一栏是打开分配给该行的pdf的目录。该代码有效,但是,每当我单击列标题时,都会出现错误:
索引超出范围。必须为非负数并且小于集合的大小。
实际上,每当我单击列文本(仅“ PDF”或任何其他列的文本)时,都会引发该错误。但是,当我在文本外部(在排序框中的任意位置)单击时,它会重新排列我的列,这没关系。有任何想法吗?
该代码有效,打开了PDF,但是我不希望用户意外单击标题文本而导致程序崩溃。这是datagridview打开pdf的代码。
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
string filename = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
if (e.ColumnIndex == 3 && File.Exists(filename))
{
Process.Start(filename);
}
}
Run Code Online (Sandbox Code Playgroud)

我尝试了下面这段代码.我不明白为什么我继续得到一个"争论超出界限"的例外.
private void Easy_Click(object sender, EventArgs e)
{
string fileData =readFile();
if (fileData.Contains(name))
{
int i = fileData.IndexOf(name);
int easyScore = i + name.Length +1;
MessageBox.Show(fileData+" "+i);
string newString = fileData.Substring(45, 48);
Easy.Text=newString;
}
}
Run Code Online (Sandbox Code Playgroud) c# ×10
winforms ×2
wpf ×2
arrays ×1
database ×1
datagridview ×1
datetime ×1
file-io ×1
mediaelement ×1
replay ×1
selection ×1
sql ×1
sql-server ×1
streamreader ×1
string ×1
textbox ×1
timer ×1
timespan ×1
variables ×1
wpfdatagrid ×1